Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code Performance Testing
- ========================
- - This is inevitably compiler/hardware dependent
- - No destructive compiler tricks (eg, inlining), so we get close to base results for each operation.
- - Tested on three systems, spanning ~10 years of hardware evolution.
- - Hardware improvements are inconsistent, with some 4x and some 20x performance gains over the 10 years.
- i,j,k are declared integers, and u,v are declared floats.
- ---------------------------------------------------------------
- Very fast operations, 1-2 cpu cycles (estimated)
- ---------------------------------------------------------------
- literal integer assignment (i = 2)
- literal integer addition (2 + 3)
- literal integer subtraction (2 - 3)
- literal integer multiply (2 * 3)
- variable integer assignment (i = j)
- variable integer addition (i + j)
- variable integer subtraction (i - j)
- variable integer multiply (i * j)
- integer comparison (i < j)
- integer comparison (i <= j)
- integer comparison (i == j)
- integer comparison (i != j)
- literal float assignment (u = 2.0f)
- literal float addition (2.0f + 3.0f)
- literal float subtraction (2.0f - 3.0f)
- literal float multiply (2.0f * 3.0f)
- variable float assignment (u = v)
- variable float addition (u + v)
- variable float subtraction (u - v)
- variable float multiply (u * v)
- float comparison (u < v)
- float comparison (u <= v)
- float comparison (u == v)
- float comparison (u != v)
- bitwise XOR (i ^ j)
- bitwise OR (i | j)
- bitwise AND (i & j)
- bitwise NOT (~i)
- ---------------------------------------------------------------
- Fast operations, < 5 cpu cycles (estimated)
- ---------------------------------------------------------------
- integer division (i / j)
- integer modulus (i % j)
- type conversion (int -> float)
- ---------------------------------------------------------------
- Medium fast operations, < 10 cpu cycles (estimated)
- ---------------------------------------------------------------
- float division (u / v)
- branching (if-else)
- type conversion (float -> int)
- ---------------------------------------------------------------
- Medium slow operations, < 25 cpu cycles (estimated)
- ---------------------------------------------------------------
- sin(), cos(), log(), exp()
- sqrt()
- floor(), ceil()
- branching (switch-case)
- ---------------------------------------------------------------
- Slow operations, upto 50 cpu cycles (estimated)
- ---------------------------------------------------------------
- function call, no args, i = f()
- function call, one arg, i = f(i)
- function call, two args, i = f(i, j)
- function call, three args, i = f(i, j, k) // no significant difference with number of args
- function call + ptr, f(*i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement