jQuery create vs clone

JavaScript performance comparison

Test case created

Info

Performance of cloning vs creating new elements with html string

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    $.testElemStr = '<div class="ui-resizable-iframefix" style="background: #fff;"></div>';
    $.testElem = $($.testElemStr);
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
create from string literal
$('body').append('<div class="ui-resizable-iframefix" style="background: #fff;"></div>');
pending…
create from string var
$('body').append($.testElemStr);
pending…
create via jQuery.clone
$('body').append($.testElem.clone());
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment