I want to measure the execution time of a function. The execution time of this function is only slightly different in the two cases. Is there any way I can accurately measure its time to distinguish the two cases? The possible solutions are:
- Use precise measurement functions. Such as
__rdtscp
orstd::chrono clock
. I tried __rdtscp, but due to the noise caused by the serializing and the granularity of time stamp counter, __tdtscp is still not accurate enough. Is there any way to reduce the noise during __rdtscp measurement? - Increase the time difference of function execution. This is what I want to do now. But once this function is changed, the background becomes less convincing.
- How to keep the cpu architecture state as consistent as possible between the execution of the replacement algorithm? Make noise reduction
- Is there a lot of noise in calling functions? Is there any way to reduce the noise in calling functions? Can calling functions in inline assembly reduce noise? Or is it new to do some other work before calling the function?
I am using a server. The version is:Linux version 4.15.0-122-generic (buildd@lcy01-amd64-010) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #124~16.04.1-Ubuntu SMP
. It is a piece of code written in C++ language. There is a function in this code, this function will perform different operations according to different privacy data (operation about cache replacement). I want to guess the privacy data based on the length of time this function is executed. Is there any way to increase the cache replacement time?
Can someone give me some advice?