M
Michael B Allen
I think I recall the modulo operator can be slow on some architectures. Or
will even trivial compiler optimization factor it out?
My specific problem is how to convert from milliseconds to seconds and
nanoseconds (POSIX timespec value):
struct timespec timeout;
timeout.tv_sec = millis / 1000; /* seconds */
timeout.tv_nsec = (millis % 1000) * 1000000; /* nanoseconds */
v.s.
timeout.tv_sec = millis / 1000; /* seconds */
/* nanoseconds */
timeout.tv_nsec = (millis - timeout.tv_sec * 1000) * 1000000;
This routine could be called quite frequently (e.g. 1000x/sec) so an
optimization might be worth it here.
Thanks,
Mike
will even trivial compiler optimization factor it out?
My specific problem is how to convert from milliseconds to seconds and
nanoseconds (POSIX timespec value):
struct timespec timeout;
timeout.tv_sec = millis / 1000; /* seconds */
timeout.tv_nsec = (millis % 1000) * 1000000; /* nanoseconds */
v.s.
timeout.tv_sec = millis / 1000; /* seconds */
/* nanoseconds */
timeout.tv_nsec = (millis - timeout.tv_sec * 1000) * 1000000;
This routine could be called quite frequently (e.g. 1000x/sec) so an
optimization might be worth it here.
Thanks,
Mike