Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0
Firefox 118
Windows
Desktop
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 74420456.0 Ops/sec
Clamp from 0 to 255 using Min/Max 62348596.0 Ops/sec
Clamp from 0 to 255 with IF 140450592.0 Ops/sec
Clamp from 0 to 255 with unary && 133946712.0 Ops/sec
Clamp in arrow function with ternary 130798080.0 Ops/sec
Clamp in regular function with MinMax 149951936.0 Ops/sec
Clamp in arrow function with IF 133430384.0 Ops/sec
Clamp in regular function with unary 116600624.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