|
|
|
|
|
by screcth
657 days ago
|
|
You could store the current date and time in a global variable and have the producers just read it atomically.
The consumer thread would then update it periodically. Timestamps will be somewhat inaccurate but it may help performance. |
|
The fastest for nanosecond precision (bonus is this is even sub nanosecond) is just to store the return value of RDTSC and let the background thread figure it all out. You don't even need to precalcuate the freq or epoch offset. Just write a couple logging messages of the rdtsc value and CLOCK_REALTIME and let the post processing figure it out.
To cut down on I/O each log message's timestamp can just be an offset from the last even.
If you are willing to push a lot of work to the background thread and even more to the post processsing step, you really don't need to do very much.