Jquery .css() vs JS.style
JavaScript performance comparison
Info
Move an element
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="test" style="position:absolute;top:100px;left:200px;">
</div>
<div id="test2" style="position:absolute;top:100px;left:200px;">
</div>
<script>
Benchmark.prototype.setup = function() {
var styles = {
display: "block",
position: "absolute",
left: 50,
top: "50%",
zIndex: 1
};
function css(myelem, styles) {
for (var style in styles) {
if (!isNaN(styles[style])) styles[style] += "px";
myelem.style[style] = styles[style];
}
}
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery |
|
pending… |
JS |
|
pending… |
JS foreach 1 |
|
pending… |
JS foreach 2 |
|
pending… |
JS foreach 3 |
|
pending… |
JS foreach function |
|
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 Maïs
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published by Gildas
- Revision 8: published by Nicholas A
- Revision 9: published by Nicholas A
- Revision 10: published by Nicholas A
- Revision 11: published
- Revision 12: published by totty90
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
0 comments