jQuery - setting attr vs data
JavaScript performance comparison
Info
Compare the speed of storing custom data via data or attr using jQuery 1.7.1.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="target"></div>
<script>
Benchmark.prototype.setup = function() {
var theDiv = $("#target");
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
attr |
|
pending… |
data |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by T.J. Crowder
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
0 comments