Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.344
Opera 73
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 715241.7 Ops/sec
Clamp from 0 to 255 using Min/Max 453328.9 Ops/sec
Clamp from 0 to 255 with IF 1570165.0 Ops/sec
Clamp from 0 to 255 with unary && 1567709.2 Ops/sec
Clamp in arrow function with ternary 910948.1 Ops/sec
Clamp in regular function with MinMax 382432.0 Ops/sec
Clamp in arrow function with IF 904061.4 Ops/sec
Clamp in regular function with unary 860777.4 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


;