Questions tagged [gettimeofday]

The function gettimeofday() can get the time as well as a timezone.

Read more in the Linux Reference.

100 questions
1
vote
1 answer

C : Why startingTime is larger than endingTime with gettimeofday()?

I'd like to measure the computing time with while loop. I'm programming with C99 version. My code is below: struct timeval startingTime,endingTime; gettimeofday(&startingTime, NULL); while(read(fd,&student,206) != 0){ …
LKM
  • 2,410
  • 9
  • 28
  • 53
1
vote
0 answers

Regarding gettimeofday shared memory access in user space.

I am trying to implement implement one approach to access the gettimeofday in user land emulator and need all possible pointers. I'm trying to map a read only region from Kernel space to User space (64 Bit) in which user space can directly poll and…
Snake
  • 63
  • 1
  • 9
1
vote
5 answers

Strange results while measuring delta time on Linux

Update: fixed delta calculations in code, still the issue remains Folks, could you please explain why I'm getting very strange results from time to time using the following code: #include #include #include int…
pachanga
  • 3,003
  • 4
  • 30
  • 45
1
vote
3 answers

Measuring execution time of selected loops

I want to measure the running times of selected loops in a C program so as to see what percentage of the total time for executing the program (on linux) is spent in these loops. I should be able to specify the loops for which the performance should…
Arjun Singri
  • 605
  • 1
  • 8
  • 17
1
vote
4 answers

objective-c gettimeofday function alternatives

I'm using gettimeofday in my program for time intervals like that: struct timeval currentTime, startTime; gettimeofday(&startTime, NULL); startTime.tv_usec /= 1000; gettimeofday(¤tTime, NULL); currentTime.tv_usec /= 1000; long int…
Gilad
  • 121
  • 1
  • 8
1
vote
1 answer

Clock_gettime showing high usage during profiling of code

I am profiling a userland application on netbsd with gprof and seeing clock_gettime using upwards of 30% cycles. Gprof does not show where it is getting called from (it shows some function which clearly does not call clock_getttime). The application…
doon
  • 2,311
  • 7
  • 31
  • 52
1
vote
2 answers

Feeding srand() with time function for Windows

I have been looking for an exact Win implémentation of the patch of code below. I am not a great programmer and the code I have was initially in UNix but I have to modify it as little as possible for Win. I understand from some googling that the…
1
vote
2 answers

gettimeofday time difference is occasionally negative

I'm writing an Object Oriented OpenGL framework in perl and I'm running into a weird issue when I measure the DeltaTime between each frame. The delta time seems to go negative every once in a while (every ~.5 seconds). I'm not sure if this is…
Francesco Noferi
  • 482
  • 7
  • 13
1
vote
3 answers

Strange errors using timeval struct and gettimeofday —because of semicolon in #define

I am getting a couple of weird compilation errors. This is for a homework assignment (help is ok). The idea is to implement a program that tests how well the user can hit "enter" once a second. I'm supposed to use gettimeofday to get some time…
MCP
  • 4,436
  • 12
  • 44
  • 53
0
votes
0 answers

Compilation error when using 'gettimeofday64' was not declared in this scope

I am trying to use gettimeofday64() instead of gettimeofday() function. #include #include int main () { struct timeval64 tim; int ret = gettimeofday64(&tim, NULL); printf("Ret = %d\n", ret); return 0; }…
Savita
  • 75
  • 4
0
votes
0 answers

How to create an instruction in module pass calling gettimeofday()?

I want to insert the gettimeofday call statement at the specified location at compile time (llvm pass) , but I don not know how to create the instruction now. Any suggestions?
gazile
  • 105
  • 6
0
votes
4 answers

Inconsistent busy waiting time in c

I have a character that should "eat" for 200 microseconds, "sleep" for 200 microseconds, and repeat, until they die, which happens if they haven't eaten for time_to_die microseconds. In the code snippet in function main indicated below, the struct…
kooru_hi
  • 43
  • 5
0
votes
1 answer

How to get local time in seconds (unix epoch)?

I am trying to get the local time in seconds (unix epoch) when a timezone is set. For e.g. 1643371200 is 2022-01-28 12:00:00 with UTC0 this can be read via gettimeofday(tv, NULL) as seconds with the timeval struct. Now let's say I set my local…
ddomnik
  • 3
  • 2
0
votes
1 answer

How to get time in milliseconds in assembly?

I was able to get it in seconds, but how to get the value of milliseconds? I am trying with the gettimeofday system call: sys_gettimeofday_ms: enter $0, $0 pushq $0 pushq $2 leaq -16(%rbp), %rdi mov $96, %rax syscall movq -16(%rbp),…
0
votes
1 answer

How can I use gettimeofday to measure the passage of time?

I'm only allowed to use this function and I'm trying to figure out a way to calculate time elapsed, any ideas? I'm confused.. # include # include # include # include int main(int argc, char*…
Abrar
  • 3
  • 5