Format string

JavaScript performance comparison

Revision 2 of this test case created

Info

Checking which formatting is best.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var text = "<--hello world-->";
    var textLen = text.length;
};
</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
innerHTML
text1 = text.substring(0, 4);
text2 = text.substring(textLen-2, textLen)
if (text1 == "<!--" && text2=="-->") text = text.substring(4, textLen - 3);
pending…
text
text1 = text.substring(0, 4);
text2 = text.substring(text.length-2, text.length)
if (text1 == "<!--" && text2=="-->") text = text.substring(4, text.length- 3);
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:

0 comments

Add a comment