Skip to content

Instantly share code, notes, and snippets.

@ericsagnes
Created March 14, 2017 11:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ericsagnes/d3770bc5e04328f943d9e60d4e64e0d4 to your computer and use it in GitHub Desktop.
Performance check of nix __functor

This test the performance of Nix __functor function calls.

Normal function result:

$ perf stat -r 10 -d nix-instantiate --eval ./test.nix -A normal
 Performance counter stats for 'nix-instantiate --eval ./test.nix -A normal' (10 runs):

         91.359343      task-clock (msec)         #    1.002 CPUs utilized            ( +-  2.66% )
                30      context-switches          #    0.329 K/sec                    ( +-  7.95% )
                 7      cpu-migrations            #    0.073 K/sec                    ( +- 22.14% )
             6,097      page-faults               #    0.067 M/sec                    ( +-  0.01% )
       294,551,144      cycles                    #    3.224 GHz                      ( +-  2.88% )  (50.64%)
   <not supported>      stalled-cycles-frontend
   <not supported>      stalled-cycles-backend
       444,512,544      instructions              #    1.51  insns per cycle          ( +-  0.67% )  (63.36%)
        90,907,884      branches                  #  995.058 M/sec                    ( +-  0.40% )  (75.67%)
           977,228      branch-misses             #    1.07% of all branches          ( +-  0.99% )  (75.72%)
       139,076,574      L1-dcache-loads           # 1522.303 M/sec                    ( +-  0.39% )  (65.33%)
         2,759,421      L1-dcache-load-misses     #    1.98% of all L1-dcache hits    ( +-  2.55% )  (25.15%)
           627,485      LLC-loads                 #    6.868 M/sec                    ( +-  5.68% )  (25.28%)
           242,037      LLC-load-misses           #   38.57% of all LL-cache hits     ( +- 14.17% )  (37.96%)

       0.091203493 seconds time elapsed                                          ( +-  2.66% ) 

With __functor:

$ perf stat -r 10 -d nix-instantiate --eval ./test.nix -A functor
 Performance counter stats for 'nix-instantiate --eval ./test.nix -A functor' (10 runs):

         94.167328      task-clock (msec)         #    1.001 CPUs utilized            ( +-  1.11% )
                31      context-switches          #    0.327 K/sec                    ( +- 11.77% )
                 6      cpu-migrations            #    0.062 K/sec                    ( +- 22.52% )
             6,946      page-faults               #    0.074 M/sec                    ( +-  0.01% )
       302,739,275      cycles                    #    3.215 GHz                      ( +-  0.90% )  (50.43%)
   <not supported>      stalled-cycles-frontend
   <not supported>      stalled-cycles-backend
       492,222,890      instructions              #    1.63  insns per cycle          ( +-  0.50% )  (63.23%)
       100,436,195      branches                  # 1066.572 M/sec                    ( +-  0.26% )  (75.58%)
           962,455      branch-misses             #    0.96% of all branches          ( +-  1.01% )  (75.76%)
       153,264,583      L1-dcache-loads           # 1627.577 M/sec                    ( +-  0.44% )  (66.30%)
         2,841,377      L1-dcache-load-misses     #    1.85% of all L1-dcache hits    ( +-  2.08% )  (25.10%)
           618,132      LLC-loads                 #    6.564 M/sec                    ( +-  8.28% )  (25.18%)
           203,862      LLC-load-misses           #   32.98% of all LL-cache hits     ( +- 15.68% )  (37.62%)

       0.094093984 seconds time elapsed                                          ( +-  1.14% ) 
with import <nixpkgs> {};
let
n = lib.id;
f = { __functor = _: lib.id; };
v = lib.range 1 50000;
in {
normal = lib.deepSeq (map n v) [];
functor = lib.deepSeq (map f v) [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment