math.clamp (v2)

Revision 2 of this benchmark created on


Description

testing clamping options

Setup

var min = 100;
    var max = 300;
    
    function clamp(value, min, max) {
      if (value > max) {
        value = max;
      } else if (value < min) {
        value = min;
      }
      return value;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
min/max
var value = Math.random() * 1000 + 1;
value = Math.min(max, Math.max(min, value));
ready
if/else
var value = Math.random() * 1000 + 1;
value = clamp(value, min, max);
ready

Revisions

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

  • Revision 1: published by Jonny Brannum on
  • Revision 2: published on
  • Revision 9: published by Maik Merten on
  • Revision 14: published by idbrii on