Concatenation vs replace

JavaScript performance comparison

Test case created

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Concat
var template = '<div class="modal hide ' + (true ? 'fade' : '') + '" ' + (true ? 'data-backdrop="static" data-keyboard="false" ' : '') + ' tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-header">' + (true && !true ? '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' : "") + '<h3 id="myModalLabel">' + ("123") + '</h3></div><div class="modal-body">' + (123 ? 456 : 789) + '</div></div>';
pending…
Replace
var template = ('<div class="modal hide {{fade}}" {{static}} tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-header">{{close}}<h3 id="myModalLabel">{{title}}</h3></div><div class="modal-body">{{content}}</div></div>').replace(/\{\{fade\}\}/g, true ? 'fade' : '').replace(/\{\{static\}\}/g, true ? 'data-backdrop="static" data-keyboard="false" ' : '').replace(/\{\{close\}\}/, true ? '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' : "").replace(/\{\{title\}\}/, "titulo").replace(/\{\{content\}\}/, "conteudo Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nam nobis aliquam nihil quas soluta nemo ad magnam animi! Veritatis magnam vero pariatur ducimus quibusdam ad sint nostrum architecto natus asperiores?");
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