Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0
Firefox 109
Mac OS X 10.15
Desktop
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 47699164.0 Ops/sec
Clamp from 0 to 255 using Min/Max 39971968.0 Ops/sec
Clamp from 0 to 255 with IF 95176112.0 Ops/sec
Clamp from 0 to 255 with unary && 95402264.0 Ops/sec
Clamp in arrow function with ternary 78517720.0 Ops/sec
Clamp in regular function with MinMax 121494440.0 Ops/sec
Clamp in arrow function with IF 77533352.0 Ops/sec
Clamp in regular function with unary 71192816.0 Ops/sec
Script Preparation code:
Tests:
  • Clamp from 0 to 255 using ternary

  • Clamp from 0 to 255 using Min/Max

  • Clamp from 0 to 255 with IF

  • Clamp from 0 to 255 with unary &&

  • Clamp in arrow function with ternary

  • Clamp in regular function with MinMax

  • Clamp in arrow function with IF

  • Clamp in regular function with unary