Hello
The following code calculates the values in nanoseconds:
Code:
for(int i=1; i<=39; i++){
long startTime = java.lang.System.nanoTime();
System.out.println("Hello world");
long endTime = java.lang.System.nanoTime();
System.out.println((endTime - startTime));
}
I would like to do the same in C:
There are some code examples in the internet such as:
Code:
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
struct timeval start, end;
long mtime, seconds, useconds;
for(int sx=1; sx<=39; sx++){
gettimeofday(&start, NULL);
printf("Hello world");
gettimeofday(&end, NULL);
printf("Elapsed time: %ld microsecons\n", end.tv_usec - start.tv_usec);
}
return 0;
}
Unfortunately this returns a 0 microseconds value. And a multiplication of 1000 doesn't change at all.
Can anyone help please?
Thx,
Troix