Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1
Mobile Safari 16
iOS 16.6.1
Mobile
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 1911781.5 Ops/sec
Clamp from 0 to 255 using Min/Max 1534482.6 Ops/sec
Clamp from 0 to 255 with IF 3792831.0 Ops/sec
Clamp from 0 to 255 with unary && 2422174.5 Ops/sec
Clamp in arrow function with ternary 1779341.4 Ops/sec
Clamp in regular function with MinMax 647478.9 Ops/sec
Clamp in arrow function with IF 1254556.5 Ops/sec
Clamp in regular function with unary 1230326.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


;