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
The target is to get all objects with name: "abc" into a single array. There are two search operations, one with a small set and one with a large set, that is basically 1000 times greater than the small set.
There is a interesting difference between the $.grep and the for-loop example, as the more items they have to compare, the closer they get in terms of performance (from 60% slower to around 20% slower)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var arrToSearchThrough_large = [];
var arrToSearchThrough_small = [{
name: "7",
res: "f"
},
{
name: "6",
res: "f"
},
{
name: "4",
res: "f"
},
{
val: "9",
res: "f"
},
{
name: "112",
res: "f"
},
{
val: "abc",
res: "f 1"
},
{
val: "ddd",
res: "f"
},
{
name: "fff",
res: "f"
},
{
name: "abc",
res: "f 2"
},
{
name: "f",
res: "f"
},
{
name: "abc",
res: "f 3"
}];
for (i = 0; i < 1000; i++)
arrToSearchThrough_large.push(arrToSearchThrough_small);
var arrResults = [];
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
1 jQuery.grep small |
| ready |
2 jQuery.each small |
| ready |
3 for-loop small |
| ready |
6 jQuery.grep large |
| ready |
7 jQuery.each large |
| ready |
8 for-loop large |
| ready |
4 jQuery.filter small |
| ready |
9 jQuery.filter large |
| ready |
5 jQuery.each #2 small |
| ready |
10 jQuery.each #2 large |
| ready |
for loop small |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.