Skip to content

Instantly share code, notes, and snippets.

@azat
Created April 3, 2019 05:04
Show Gist options
  • Select an option

  • Save azat/2168ee8cc3a29397be63dcf9894f7075 to your computer and use it in GitHub Desktop.

Select an option

Save azat/2168ee8cc3a29397be63dcf9894f7075 to your computer and use it in GitHub Desktop.
#include <event2/event.h>
#include <event2/util.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct timeval tv;
size_t n = argc == 2 ? atoll(argv[1]) : 1<<20;
struct event_base *base = event_base_new();
for (size_t i = 0; i < n; ++i) {
#ifdef CACHED
event_base_gettimeofday_cached(base, &tv);
#else
evutil_gettimeofday(&tv, 0);
#endif
}
return 0;
}
@azat
Copy link
Author

azat commented Apr 3, 2019

$ gcc -DCACHED -levent_core -O3 /tmp/le-gettimeofday.c
$ perf stat ./a.out $((20<<20))

 Performance counter stats for './a.out 20971520':

            415.21 msec task-clock                #    0.999 CPUs utilized
                 2      context-switches          #    0.005 K/sec
                 0      cpu-migrations            #    0.000 K/sec
                67      page-faults               #    0.161 K/sec
     1,387,245,094      cycles                    #    3.341 GHz
     2,184,475,082      instructions              #    1.57  insn per cycle
       441,043,566      branches                  # 1062.220 M/sec
            12,901      branch-misses             #    0.00% of all branches

       0.415609543 seconds time elapsed

       0.415458000 seconds user
       0.000000000 seconds sys


@azat
Copy link
Author

azat commented Apr 3, 2019

$ gcc -levent_core -O3 /tmp/le-gettimeofday.c
$ perf stat ./a.out $((20<<20))

 Performance counter stats for './a.out 20971520':

            378.13 msec task-clock                #    0.999 CPUs utilized
                 1      context-switches          #    0.003 K/sec
                 0      cpu-migrations            #    0.000 K/sec
                67      page-faults               #    0.177 K/sec
     1,240,030,026      cycles                    #    3.279 GHz
     1,637,903,082      instructions              #    1.32  insn per cycle
       294,022,433      branches                  #  777.577 M/sec
            13,187      branch-misses             #    0.00% of all branches

       0.378598087 seconds time elapsed

       0.375123000 seconds user
       0.003309000 seconds sys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment