I want to convert my timeval struct from seconds to nanoseconds, what is the best algorithm to achieve this?
Asked
Active
Viewed 3,408 times
-6
-
1Multiply the seconds by one billion? Although this won't give you any more precision. – ForceBru Feb 02 '17 at 16:48
-
http://www.cs.loyola.edu/~jglenn/702/S2008/Projects/P3/time.html should help.. – Jeyaram Feb 02 '17 at 16:48
-
1Multiplication by 1000000000? – R.. GitHub STOP HELPING ICE Feb 02 '17 at 16:48
-
1I'm voting to close this question as off-topic because converting from seconds to nanoseconds is a simple multiplication – KevinDTimm Feb 02 '17 at 17:08
1 Answers
2
I would suggest this:
uint64_t nanosec(struct timeval t) { /* Calculate nanoseconds in a timeval structure */
return t.tv_sec * 1000000000 + t.tv_usec * 1000;
}

Jack Humphries
- 13,056
- 14
- 84
- 125

jj_3684
- 21
- 1