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
What if we only do reading of data-attributes. Since most are commming generated from databases..
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="mydiv"></div>
var div = document.getElementById('mydiv');
var $div = $(div);
var Data = function() {
var warehouse = {};
var count = 1;
return {
reset: function() {
count = 1;
warehouse = {};
},
set: function (dom, data) {
if (!dom.__data) {
dom.__data = "hello" + count++;
}
warehouse[dom.__data] = data;
},
get: function(dom) {
return warehouse[dom.__data];
}
};
}();
Data.set(div, {po: 'bla bla ', ta: '123456789', to: 'The red chick jumps over the white chicke'});
div.setAttribute('data-po', 'bla bla');
div.setAttribute('data-ta', '123456789');
div.setAttribute('data-to', 'The red chick jumps over the white chicken');
Ready to run.
Test | Ops/sec | |
---|---|---|
old school setAttribute |
| ready |
DIY Data |
| ready |
HTML5 dataset |
| ready |
jQuery .data() |
| ready |
old school [] |
| ready |
jQuery $.data() |
| ready |
jQuery .attr() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.