开发者

measuring speed of a system call

开发者 https://www.devze.com 2023-01-17 05:42 出处:网络
I am trying to optimize our gettimeofday() system ca开发者_开发技巧ll on Redhat Linux. By their documentation it can be speed by running the call in the user land using virtual dynamic shared object

I am trying to optimize our gettimeofday() system ca开发者_开发技巧ll on Redhat Linux. By their documentation it can be speed by running the call in the user land using virtual dynamic shared object (VDSO). I was curious how can I mesure the speed of the call in the first place? I would like to make the change and then compare it against my previous results


Pseudocode:

  1. call gettimeofday() and save result in a
  2. call gettimeofday() a million times
  3. call gettimeofday() and save result in b
  4. Calculate (b-a)/1,000,000

Rationale: The two bounding calls to gettimeofday() should not make much of an impact on the loop. It may feel strange to call the function that you want to time but that's OK.


Maybe

strace -T


If your on an Intel platform, IAPerf.H has some macros which make high resolution timing straightforward.

   PERFINITMHZ(1200) // Set the clockspeed of your processor
   PERFSTART
   gettimeofday();
   PERFSTOP
   PERFREPORT

It's using the Time Stamp Register to get the time so you avoid the cost of a sys call and get accurate timing. You may still want to call gettimeofday a million times and divide the result if the results aren't accruate enough.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号