Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/117.0.5938.117 Mobile/15E148 Safari/604.1
Chrome Mobile iOS 117
iOS 16.6
Mobile
one year ago
Test name Executions per second
Clamp from 0 to 255 using ternary 1428178.1 Ops/sec
Clamp from 0 to 255 using Min/Max 765306.2 Ops/sec
Clamp from 0 to 255 with IF 2490304.0 Ops/sec
Clamp from 0 to 255 with unary && 2079454.2 Ops/sec
Clamp in arrow function with ternary 1251152.9 Ops/sec
Clamp in regular function with MinMax 645154.8 Ops/sec
Clamp in arrow function with IF 811453.7 Ops/sec
Clamp in regular function with unary 1548292.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


;