J
Beware:
Jorge meinte:
Can't help - I always have to think of Bela Lugosi [1]...
Bevare, Bevaaare :
How to speed up (up to 3x !) global object's method calls [for
example, Math.method()]: by aliasing them in a local var:
<http://jorgechamorro.com/cljs/033/>
How to speed up (up to 3x !) global object's method calls [for
example, Math.method()]: by aliasing them in a local var:
<http://jorgechamorro.com/cljs/033/>
Chrome 1.0.154.43 on Windows NT
Test Ops/sec
full local aliasing 676170
full "global" aliasing 679676
partial local aliasing 696285
partial "global" aliasing 693338
no aliasing 700752
There goes the idea that accessing globals is universally slower.
Firefox 3.0.5 on Intel Mac OS X 10.5
Test Ops/sec
Ready
full local aliasing 235197
full "global" aliasing 161481
partial local aliasing 181518
partial "global" aliasing 140683
no aliasing 94672
-------------------
Safari 3.2 on Intel Mac OS X 10_5_5
Test Ops/sec
full local aliasing 377306
full "global" aliasing 256909
partial local aliasing 234481
partial "global" aliasing 184976
no aliasing 143375
Bottom line, I wouldn't put an *extra* effort into achieving full local
aliasing.
But see what happens in the iPhone:
Safari 3.1.1 on iPhone OS 2.2
Test Ops/sec
full local aliasing 12780
full "global" aliasing 7287
partial local aliasing 7601
partial "global" aliasing 5604
no aliasing 3738
3.4x !![]()
Agreed (that's why I stressed the "extra"). And it also devalues the
"nowadays browsers are fast enough for library x" argument.
Well, it's good to know (just in case) about this aliasing business,
but, still, it doesn't matter very much if all a script takes to
execute is (usually) 0.1s or 0.34s, isn't it ? There's quite a lot of
truth (nowadays, but not necessarily in the future) in this: "if
JavaScript were infinitely fast, most web applications would run at
about the same speed":
If JavaScript was infinitely fast, I would definitely abstract it with
another language with tail call elimination. As it stands, JavaScript
is not fast enough.
IIRC, Gregor's got an Opera that's infinitely fast. It's so amazing.
Jorge said:(...)
How to speed up (up to 3x !) global object's method calls [for
example, Math.method()]: by aliasing them in a local var:
<http://jorgechamorro.com/cljs/033/>
[email protected] said:Jorge said:(...)
How to speed up (up to 3x !) global object's method calls [for
example, Math.method()]: by aliasing them in a local var:
<http://jorgechamorro.com/cljs/033/>
A video explaining this very same thing (among others):
"Speed Up Your JavaScript"
by Nicholas C. Zakas:
(@ ~11m0s)
[email protected] said:Jorge said:(...)
How to speed up (up to 3x !) global object's method calls [for
example, Math.method()]: by aliasing them in a local var:
<http://jorgechamorro.com/cljs/033/>A video explaining this very same thing (among others):
"Speed Up Your JavaScript"
by Nicholas C. Zakas:
(@ ~11m0s)
The "up to 3x" part might require a particularly braindead browser
I just ran the benchmark in Opera and Chrome, and while there is a
difference, it's closer to 10% at the most.
Mr. Zakas does have some points, but not all of them hold up in an
optimized engine, and none of them apply all the time (if it's not in
a loop, don't bother optimizing). Taking all he says as gospel will
lead to a lot of premature optimization.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.