Skip to content
João Medeiros edited this page Apr 8, 2023 · 47 revisions

Performance Measure

C

SYNOPSIS
       #include <time.h>

       int clock_gettime(clockid_t clockid, struct timespec *tp);
struct timespec {
    time_t   tv_sec;        /* seconds */
    long     tv_nsec;       /* nanoseconds */
};
#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    struct timespec a, b;
    unsigned int t;

    clock_gettime(CLOCK_MONOTONIC, &b);
    sleep(1);
    clock_gettime(CLOCK_MONOTONIC, &a);

    t = (a.tv_sec * 1e9 + a.tv_nsec) - (b.tv_sec * 1e9 + b.tv_nsec);

    printf("%u\n", t);

    return 0;
}
int search(int *v, unsigned int n, int k)
{
    while (n-- > 0)
    {
        if (v[n] == k)
            return n;
    }
    return -1;
}

int main(int argc, char **argv)
{
    for ()
    return 0;
}

Python

Java

import java.lang.Thread;

public class Time
{
    public static void main(String[] args)
    {
        long a, b, t;

        b = System.nanoTime();
        try 
        {
            java.lang.Thread.sleep(1000);
        } 
        catch(InterruptedException e)
        {
            System.out.println(e);
        }
        a = System.nanoTime();

        t = (a - b) / 1000;

        System.out.println(t);
    }
}

Clone this wiki locally