Are there links to any such tests? As in when, which browser,
what machine and so on these tests were run?
Try it for yourself, any browser. The machine is not important when
gathering relative speed values:-
The baseless claim that 'eval is evil'
looks like it's been going on for years now.
eval is evil and always has been. This group continues to actively
campaign against its abuse because it server to discourage new script
authors from learning to do things properly. People promote eval because
it "works", in the broadest possible sense of the word, but is its use
correct? Take the code you posted to this thread:-
var newStr = eval(s1) + eval(s2);
Apart from the fact that, when it "works", it still does not fulfil the
OPs requirement as the output is of numeric type and not a string, which
brings into question the use of "newStr" as an identifier for the
result. The eval function may react in almost any way if the s1 or s2
values are no actually strings that represent numbers in JavaScript
source code. When so many alternative string to number type-converting
methods exist and they _all_ have predictable, specified and documented
output if the input does not happen to be a string representation of a
number, then eval is objectively the worst string to number
type-converting method to use. So why promote its use? Because it
"works" (when it works)?
But eval abuse does not only shelter people from learning better
techniques, it also encourages a "mystical incantation" approach to
programming, resulting in people wrapping the eval function around all
sorts of weird and wonderful expressions, and because doing that won't
necessarily make things worse and will often mask errors this habit
propagates throughout their code.
No one benefits from the use of eval, not the user (burdened with slow,
processor intensive code and excessive downloads), not the programmer
(screened from learning to do their job well) and definitely not the
posters on this group. If that results in a pejorative epithet being
attached to the eval function then that is not really surprising.
Richard.