开发者

In Javascript/jQuery, is there a difference in rendering performance if I condense my code into "one-liners"?

开发者 https://www.devze.com 2022-12-22 07:17 出处:网络
Is there a difference in performance (I am not asking about readability) if I condense my code into one line versus two?

Is there a difference in performance (I am not asking about readability) if I condense my code into one line versus two?

For example:

var slide = 'images/' + n + '.png';

$('img').attr('src',slide);

versus

$('img').attr('src','images/' + n + '.png');

Personally, I like fewer lines o开发者_如何学编程f code. Often, I am the only one reading my code, so communicating intent is not as important.

I am curious if the Javascript interpreter executes one of the above options faster (even though this is a classic micro-optimization example).


No difference in rendering performance, at all.


Micro-optimization doesn't half say it. :-)

The answer will depend a lot on the interpreter involved. I wouldn't be surprised if IE's interpreter had a very very very very very very (...continue saying "very" for a while...) very slight, impossible to detect difference. Chrome's V8, on the other hand, is certain not to.

In real terms, though? No, no difference at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消