jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
@wolframkriesing wondered what the most efficient unique
function for Array
would be: http://twitter.com/wolframkriesing/status/83847205189980160
Let’s find out!
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js">
</script>
<script src="https://raw.github.com/mootools/mootools-more/master/Source/Types/Array.Extras.js">
</script>
var array = [],
i;
for (i = 0; i < 10000; ++i) array[i] = Math.random();
function mootools_unique(arr) {
var target = [];
for (var i = 0, a = arr.length; i < a; i++) {
var obj = arr[i];
if (target.indexOf(obj) == -1) {
target.push(obj);
}
}
return target;
}
Benchmark.prototype.setup = function() {
var mu = mootools_unique; // avoid scope lookup penalty in the test itself
};
Ready to run.
Test | Ops/sec | |
---|---|---|
Using indexOf - O(n2) |
| ready |
Using indexOf and ~ - O(n2) |
| ready |
Using a map - O(n) |
| ready |
Using sort and filter - O((n lg n) + n) |
| ready |
Using better indexOf logic |
| ready |
Using simpler in logic |
| ready |
Moo-More unique |
| ready |
MooTools forEach inlined |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.