1

I am using some string which contains an html. As follows

var pagerHtml = '<span>No.Of Records</span><select class="rmselect" id="records" ><option value="10">10</option><option value="20">20</option><option value="40">40</option><option value="80">80</option><option value="100">100</option></select>';

Another is with " and escape sequence \" for " in the html as follows

var pagerHtml = "<span>No.Of Records</span><select class=\"rmselect\" id=\"records\" ><option value=\"10\">10</option><option value=\"20\">20</option><option value=\"40\">40</option><option value=\"80\">80</option><option value=\"100\">100</option></select>";

And I am writing this html to a div using jquery

Which one gives the better performance while parsing?

Is there any performance difference on parsing escape sequence?

6
  • Can you make a benchmark? I expect there to be no difference, but you never know. Commented Aug 6, 2013 at 8:48
  • The only way to get the answer is by testing. That implies using a browser. That implies browser have engines that execute javascript. That implies it depends on the browser's engine implementaton. That implies the result will vary from browser to browser. Given the fact it's such a trivial operation and the difference is negligible, why do you even ask before you test? Commented Aug 6, 2013 at 8:48
  • It just has few extra characters to look into that's all , I don't believe that's gonna make any difference! Commented Aug 6, 2013 at 8:52
  • 1
    jsperf.com/so-18075520 Commented Aug 6, 2013 at 8:55
  • 1
    @Spokey you might as well had thrown a coin... that benchmark is completely irrelevant to everything here. First because JSPerf only tests runtime performance and second your tests use extremely slow .html operation which will shadow any other operation. Commented Aug 6, 2013 at 8:58

2 Answers 2

3

Parsing does not affect runtime performance even in interpreters like older IE, they are equal.

If you try to implement an interpreter or compiler, you will quickly realize that it doesn't make sense to analyze the program as a string. Therefore the first thing you do is to parse it before doing anything else. After you have parsed it, you have already parsed it and these things cannot possibly make a difference.

Sign up to request clarification or add additional context in comments.

Comments

2

Almost certainly no difference. This is a very low-level optimised thing. There are lots of other performance concerns and this isn't one.

2 Comments

No, there is nothing more to say. This is a very common, fundamental operation and will be very heavily optimised by the language runtime / parser.
If you mean what are the 'lots of other performance concerns' then people spend whole careers and write whole books on the subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.