Clamping

Benchmark created on


Preparation HTML

<script>
  function clamp1(num, min, max) {
    return Math.max(Math.min(max, num), min)
  }
  
  function clamp2(num, min, max) {
    return num < min? min
         : num > max? max
         :            num
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Math
clamp1(11, 0, 10)
ready
Ternary
clamp2(11, 0, 10)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.