jQuery .clone(true) vs. rebinding.
JavaScript performance comparison
Preparation code
<div id="#foo">Hello World</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var x = 1
$foo = $('#foo');
var bindIt = function(){
$foo.on('customEvent', function(){
x++;
});
};
bindIt();
var $fooDetach = $foo.detach();
};
Benchmark.prototype.teardown = function() {
$('#foo').off('customEvent');
delete $foo;
delete $fooDetach;
};
</script>
Preparation code output
Hello World
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
clone() then rebind |
|
pending… |
clone(true) |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments