Skip to content

Instantly share code, notes, and snippets.

@Gavinok
Created August 2, 2022 19:51
Show Gist options
  • Save Gavinok/8a324c203088dddbe87fe0e1bd34acd0 to your computer and use it in GitHub Desktop.
Save Gavinok/8a324c203088dddbe87fe0e1bd34acd0 to your computer and use it in GitHub Desktop.
valgrind clamping benchmark

Valgrind clamping comparison

Before clamping

#define CLAMP(X) ((X > 0) ? X : 0)
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw function
8,400,000 (48.20%) 9 ( 0.59%) 9 ( 0.60%) 1,320,000 (43.33%) 11,160 (84.72%) 11,135 (88.25%) 300,000 (13.08%) 0 0 ???:rgbtoycbcr2
5,280,000 (30.29%) 5 ( 0.33%) 5 ( 0.33%) 660,000 (21.66%) 0 0 960,000 (41.84%) 0 0 ???:ycbcrtorgb2
3,534,136 (20.28%) 18 ( 1.17%) 18 ( 1.20%) 1,017,311 (33.39%) 2 ( 0.02%) 0 1,018,314 (44.38%) 0 0 ???:applyModifierPPM
56,580 ( 0.32%) 6 ( 0.39%) 6 ( 0.40%) 10,929 ( 0.36%) 100 ( 0.76%) 100 ( 0.79%) 7 ( 0.00%) 0 0 /usr/src/debug/glibc/elf/dl-tunables.c:_GI__tunablesinit
28,070 ( 0.16%) 18 ( 1.17%) 18 ( 1.20%) 8,832 ( 0.29%) 230 ( 1.75%) 158 ( 1.25%) 3,436 ( 0.15%) 7 ( 0.83%) 4 ( 0.56%) /usr/src/debug/glibc/elf/dl-lookup.c:dolookupx
24,398 ( 0.14%) 13 ( 0.85%) 13 ( 0.87%) 4,885 ( 0.16%) 99 ( 0.75%) 89 ( 0.71%) 2,416 ( 0.11%) 8 ( 0.95%) 0 /usr/src/debug/glibc/elf/dl-lookup.c:dllookupsymbolx
19,830 ( 0.11%) 28 ( 1.83%) 28 ( 1.87%) 5,078 ( 0.17%) 418 ( 3.17%) 399 ( 3.16%) 2,126 ( 0.09%) 256 (30.30%) 244 (34.17%) usr/src/debug/glibc/elf../sysdeps/x8664/dl-machine.h:dlrelocateobject

before with max cap

#define CLAMP(X) (X > 255 ? 255 : ((X > 0) ? X : 0))

--------------------------------------------------------------------------------
Ir                  I1mr           ILmr           Dr                 D1mr            DLmr            Dw                 D1mw         DLmw         
--------------------------------------------------------------------------------
19,408,968 (100.0%) 1,536 (100.0%) 1,497 (100.0%) 3,166,636 (100.0%) 13,173 (100.0%) 12,617 (100.0%) 2,414,378 (100.0%) 844 (100.0%) 714 (100.0%)  PROGRAM TOTALS

--------------------------------------------------------------------------------
Ir                 I1mr        ILmr        Dr                 D1mr            DLmr            Dw                 D1mw         DLmw          file:function
--------------------------------------------------------------------------------
8,400,000 (43.28%)  9 ( 0.59%)  9 ( 0.60%) 1,320,000 (41.68%) 11,160 (84.72%) 11,135 (88.25%)   300,000 (12.43%)   0            0           ???:rgb_to_ycbcr2
7,260,000 (37.41%)  7 ( 0.46%)  7 ( 0.47%)   780,000 (24.63%)      0               0          1,080,000 (44.73%)   0            0           ???:ycbcr_to_rgb2
3,534,136 (18.21%) 17 ( 1.11%) 17 ( 1.14%) 1,017,311 (32.13%)      2 ( 0.02%)      0          1,018,314 (42.18%)   0            0           ???:applyModifierPPM
   56,580 ( 0.29%)  6 ( 0.39%)  6 ( 0.40%)    10,929 ( 0.35%)    100 ( 0.76%)    100 ( 0.79%)         7 ( 0.00%)   0            0           /usr/src/debug/glibc/elf/dl-tunables.c:__GI___tunables_init
   28,070 ( 0.14%) 18 ( 1.17%) 18 ( 1.20%)     8,832 ( 0.28%)    230 ( 1.75%)    158 ( 1.25%)     3,436 ( 0.14%)   7 ( 0.83%)   4 ( 0.56%)  /usr/src/debug/glibc/elf/dl-lookup.c:do_lookup_x
   24,398 ( 0.13%) 13 ( 0.85%) 13 ( 0.87%)     4,885 ( 0.15%)     99 ( 0.75%)     89 ( 0.71%)     2,416 ( 0.10%)   8 ( 0.95%)   0           /usr/src/debug/glibc/elf/dl-lookup.c:_dl_lookup_symbol_x
   19,830 ( 0.10%) 28 ( 1.82%) 28 ( 1.87%)     5,078 ( 0.16%)    418 ( 3.17%)    399 ( 3.16%)     2,126 ( 0.09%) 256 (30.33%) 244 (34.17%)  /usr/src/debug/glibc/elf/../sysdeps/x86_64/dl-machine.h:_dl_relocate_object

--------------------------------------------------------------------------------
The following files chosen for auto-annotation could not be found:
--------------------------------------------------------------------------------
  /usr/src/debug/glibc/elf/../sysdeps/x86_64/dl-machine.h
  /usr/src/debug/glibc/elf/dl-lookup.c
  /usr/src/debug/glibc/elf/dl-tunables.c

With clamping

inline int32_t clamp(int32_t x){
  uint32_t y;
  if ((y = x>>8))
    x = ~y;
  return x;
}

--------------------------------------------------------------------------------
Ir                 I1mr        ILmr        Dr                 D1mr            DLmr            Dw                 D1mw         DLmw          file:function
--------------------------------------------------------------------------------
8,400,000 (41.73%)  9 ( 0.59%)  9 ( 0.60%) 1,320,000 (44.20%) 11,160 (84.72%) 11,135 (88.25%)   300,000 (13.43%)   0            0           ???:rgb_to_ycbcr2
7,980,000 (39.64%)  7 ( 0.46%)  7 ( 0.47%)   600,000 (20.09%)      0               0            900,000 (40.28%)   0            0           ???:ycbcr_to_rgb2
3,534,136 (17.56%) 18 ( 1.17%) 18 ( 1.20%) 1,017,311 (34.06%)      2 ( 0.02%)      0          1,018,314 (45.57%)   0            0           ???:applyModifierPPM
   56,580 ( 0.28%)  6 ( 0.39%)  6 ( 0.40%)    10,929 ( 0.37%)    100 ( 0.76%)    100 ( 0.79%)         7 ( 0.00%)   0            0           /usr/src/debug/glibc/elf/dl-tunables.c:__GI___tunables_init
   28,070 ( 0.14%) 18 ( 1.17%) 18 ( 1.20%)     8,832 ( 0.30%)    230 ( 1.75%)    158 ( 1.25%)     3,436 ( 0.15%)   7 ( 0.83%)   4 ( 0.56%)  /usr/src/debug/glibc/elf/dl-lookup.c:do_lookup_x
   24,398 ( 0.12%) 13 ( 0.85%) 13 ( 0.87%)     4,885 ( 0.16%)     99 ( 0.75%)     89 ( 0.71%)     2,416 ( 0.11%)   8 ( 0.95%)   0           /usr/src/debug/glibc/elf/dl-lookup.c:_dl_lookup_symbol_x

--------------------------------------------------------------------------------
The following files chosen for auto-annotation could not be found:
--------------------------------------------------------------------------------
  /usr/src/debug/glibc/elf/dl-lookup.c
  /usr/src/debug/glibc/elf/dl-tunables.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment