math.clamp (v9)

Revision 9 of this benchmark created by Maik Merten on


Setup

var min = 100;
  var max = 300;

Test runner

Ready to run.

Testing in
TestOps/sec
ternary clamp
var value = Math.random() * 1000 + 1;
value = value > max ? max : (value < min ? min : value);
ready
if/else
var value = Math.random() * 1000 + 1;
if (value > max) {
  value = max;
} else if (value < min) {
  value = min;
}
ready
min/max
var value = Math.random() * 1000 + 1;
value = Math.min(max, Math.max(min, value));
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