Sorceress

Code Performance Testing

Jul 8th, 2017
194
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Code Performance Testing
  2. ========================
  3.  
  4. - This is inevitably compiler/hardware dependent
  5. - No destructive compiler tricks (eg, inlining), so we get close to base results for each operation.
  6.  
  7. - Tested on three systems, spanning ~10 years of hardware evolution.
  8. - Hardware improvements are inconsistent, with some 4x and some 20x performance gains over the 10 years.
  9.  
  10. i,j,k are declared integers, and u,v are declared floats.
  11.  
  12. ---------------------------------------------------------------
  13. Very fast operations, 1-2 cpu cycles (estimated)
  14. ---------------------------------------------------------------
  15.  
  16. literal integer assignment (i = 2)
  17. literal integer addition (2 + 3)
  18. literal integer subtraction (2 - 3)
  19. literal integer multiply (2 * 3)
  20.  
  21. variable integer assignment (i = j)
  22. variable integer addition (i + j)
  23. variable integer subtraction (i - j)
  24. variable integer multiply (i * j)
  25.  
  26. integer comparison (i < j)
  27. integer comparison (i <= j)
  28. integer comparison (i == j)
  29. integer comparison (i != j)
  30.  
  31. literal float assignment (u = 2.0f)
  32. literal float addition (2.0f + 3.0f)
  33. literal float subtraction (2.0f - 3.0f)
  34. literal float multiply (2.0f * 3.0f)
  35.  
  36. variable float assignment (u = v)
  37. variable float addition (u + v)
  38. variable float subtraction (u - v)
  39. variable float multiply (u * v)
  40.  
  41. float comparison (u < v)
  42. float comparison (u <= v)
  43. float comparison (u == v)
  44. float comparison (u != v)
  45.  
  46. bitwise XOR (i ^ j)
  47. bitwise OR (i | j)
  48. bitwise AND (i & j)
  49. bitwise NOT (~i)
  50.  
  51. ---------------------------------------------------------------
  52. Fast operations, < 5 cpu cycles (estimated)
  53. ---------------------------------------------------------------
  54.  
  55. integer division (i / j)
  56. integer modulus (i % j)
  57. type conversion (int -> float)
  58.  
  59. ---------------------------------------------------------------
  60. Medium fast operations, < 10 cpu cycles (estimated)
  61. ---------------------------------------------------------------
  62.  
  63. float division (u / v)
  64. branching (if-else)
  65. type conversion (float -> int)
  66.  
  67. ---------------------------------------------------------------
  68. Medium slow operations, < 25 cpu cycles (estimated)
  69. ---------------------------------------------------------------
  70.  
  71. sin(), cos(), log(), exp()
  72. sqrt()
  73. floor(), ceil()
  74. branching (switch-case)
  75.  
  76. ---------------------------------------------------------------
  77. Slow operations, upto 50 cpu cycles (estimated)
  78. ---------------------------------------------------------------
  79.  
  80. function call, no args, i = f()
  81. function call, one arg, i = f(i)
  82. function call, two args, i = f(i, j)
  83. function call, three args, i = f(i, j, k) // no significant difference with number of args
  84. function call + ptr, f(*i)
RAW Paste Data