Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118
Windows
Desktop
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 401731.2 Ops/sec
Clamp from 0 to 255 using Min/Max 296787.0 Ops/sec
Clamp from 0 to 255 with IF 898611.4 Ops/sec
Clamp from 0 to 255 with unary && 893755.0 Ops/sec
Clamp in arrow function with ternary 520879.7 Ops/sec
Clamp in regular function with MinMax 249398.3 Ops/sec
Clamp in arrow function with IF 522927.7 Ops/sec
Clamp in regular function with unary 519101.6 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


;