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
<script src="https://rawgit.com/facebook/immutable-js/master/dist/immutable.min.js"></script>
<script>
var iterator = (function () {
var min = Math.min;
Iterator.prototype = {
map: function (f) {
return new Iterator(compose(f, this.at), this.length);
},
take: function (n) {
return new Iterator(this.at, min(n, this.length));
},
toArray: function () {
var at = this.at;
var length = this.length;
var array = new Array(length);
var index = 0;
while (index < length) array[index] = at(index++);
return array;
}
};
return iterator;
function compose(f, g) {
return function (x) {
return f(g(x));
};
}
function iterator(a) {
return new Iterator(function (index) {
return a[index];
}, a.length);
}
function Iterator(at, length) {
this.at = at;
this.length = length;
}
}());
var fusion = (function () {
var min = Math.min;
Iterator.prototype = {
map: function (f) {
return new MapIterator([f, this.at], this.length);
},
take: take,
toArray: toArray
};
MapIterator.prototype = {
map: function (f) {
return new MapIterator([f].concat(this.fs), this.length);
},
take: take,
toArray: toArray
};
return iterator;
function compose(f, g) {
return function (x) {
return f(g(x));
};
}
function iterator(a) {
return new Iterator(function (index) {
return a[index];
}, a.length);
}
function Iterator(at, length) {
this.at = at;
this.length = length;
}
function MapIterator(fs, length) {
this.fs = fs;
this.at = fs.reduce(compose);
this.length = length;
}
function take(n) {
return new Iterator(this.at, min(n, this.length));
}
function toArray() {
var at = this.at;
var length = this.length;
var array = new Array(length);
var index = 0;
while (index < length) array[index] = at(index++);
return array;
}
}());
</script>
function square(x) {
return x * x;
}
function increment(x) {
return x + 1;
}
var arr = new Array(10000);
for (var i=0; i<arr.length; i++)
arr[i] = Math.random();
var immu = Immutable.Seq(arr).map(square).map(increment).take(8000),
lazy = iterator(arr).map(square).map(increment).take(8000),
fuse = fusion(arr).map(square).map(increment).take(8000)
var l=0;
l=0;
Ready to run.
Test | Ops/sec | |
---|---|---|
Immutable.js iteration |
| ready |
Lazy iteration |
| ready |
Lazy short-cut fusion iteration |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.