Divide or modulo
JavaScript performance comparison
Preparation code
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
negativeDiv = function(chanceOfNegative) {
if (Math.random() > 1 / (chanceOfNegative || 2)) {
return 1
} else {
return -1
}
}
negativeMod = function(chanceOfNegative) {
if (_.random(100) % (chanceOfNegative || 2) !== 0) {
return 1
} else {
return -1
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
divide |
|
pending… |
modulo |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments