Optimising DOM Access
JavaScript performance comparison
Info
DOM manipulation seems expensive.
This is to see how much processor usage can be saved by only touching the DOM when needed.
Preparation code
<div id="TargetDIV">Test DIV</div>
<script>
Benchmark.prototype.setup = function() {
var targetDIV = document.getElementById("TargetDIV");
var posX =0, prevPosX=0;
};
</script>
Preparation code output
Test DIV
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Un-optimised. Move on every iteration. |
|
pending… |
Optimised. Only move when necessary |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments