c++ - std::time(NULL) performance -
How fast is std :: time (null)
comparing read-only variable ? I am planning to use std :: time (NULL)
in the low latency application for trading. I'm wondering what's better:
- Just
std :: time (NULL)
call - in special bag (which is already I have to update the global variable from time to time and assign to
std :: time (NULL)
, read this thread from all the other places with another thread < / Ul>
The second evaluation is less accurate, but will it be faster? I do not need the accuracy, I need speed, if another approach is understood then how should I declare my variable? Unstable std :: time_t
or std :: atomic & lt; Std :: time_t & gt;
or something else? I write this variable with a thread and read it with many threads.
Utility thread (or process) that clock a few times a second (which meets your accuracy demand ) And saves it in memory.
Apply an interface that gives time by reading it from this place instead of making an expensive OS call and potentially switching context in the kernel (the OS Are based on the platform for its development). For you, this interface will be a class template with a policy to avoid virtual calls and create qualified calls for inlining.
You do it in such a way that you can easily duplicate and can change the implementation of such unit tests, or later.
Comments
Post a Comment