Run details:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36
Chrome Mobile 117
Android
Mobile
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 1403320.8 Ops/sec
Clamp from 0 to 255 using Min/Max 910200.1 Ops/sec
Clamp from 0 to 255 with IF 3195106.2 Ops/sec
Clamp from 0 to 255 with unary && 3192158.8 Ops/sec
Clamp in arrow function with ternary 1801179.6 Ops/sec
Clamp in regular function with MinMax 804240.6 Ops/sec
Clamp in arrow function with IF 1803939.9 Ops/sec
Clamp in regular function with unary 1804405.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