JFYI

128 views
Skip to first unread message

Jorge

unread,
May 25, 2012, 5:50:53 AM5/25/12
to nod...@googlegroups.com
$ time node -e 'i=1e7; while(i--);'

real 0m2.029s
user 0m2.008s
sys 0m0.016s

$ time jsc -e 'i=1e7; while(i--);'

real 0m0.048s
user 0m0.041s
sys 0m0.006s

$ time node -e '0'

real 0m0.049s
user 0m0.025s
sys 0m0.010s

$ time jsc -e '0'

real 0m0.011s
user 0m0.005s
sys 0m0.006s

--
Jorge.

Bradley Meck

unread,
May 25, 2012, 6:09:24 AM5/25/12
to nod...@googlegroups.com
I think you should be comparing with d8 more than node ... node pulls in a lot of stuff that jsc would never dream of.

Jorge

unread,
May 25, 2012, 7:17:20 AM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 12:09 PM, Bradley Meck wrote:

> I think you should be comparing with d8 more than node ... node pulls in a lot of stuff that jsc would never dream of.

Right, but, what's with the 'i=1e7; while(i--);' ?
--
Jorge.

Fedor Indutny

unread,
May 25, 2012, 7:18:35 AM5/25/12
to nod...@googlegroups.com
Try this:

time node -e '(function() { var i=1e7; while(i--); })()'

The thing is that jsc is somehow optimizing access to the global variables.

Cheers,
Fedor.



--
Jorge.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

mscdex

unread,
May 25, 2012, 9:01:36 AM5/25/12
to nodejs
Is this tried with node master branch or node 0.6.x?

Jorge

unread,
May 25, 2012, 10:55:17 AM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 1:18 PM, Fedor Indutny wrote
>> On Fri, May 25, 2012 at 3:17 PM, Jorge <jo...@jorgechamorro.com> wrote:
>>> On May 25, 2012, at 12:09 PM, Bradley Meck wrote:
>>>
>>> I think you should be comparing with d8 more than node ... node pulls in a lot of stuff that jsc would never dream of.
>>
>> Right, but, what's with the 'i=1e7; while(i--);' ?
>
> Try this:
>
> time node -e '(function() { var i=1e7; while(i--); })()'
>
> The thing is that jsc is somehow optimizing access to the global variables.

Much better:

$ time node -e '(function() { var i=1e7; while(i--); })()'

real 0m0.092s
user 0m0.077s
sys 0m0.012s

$ time jsc -e '(function() { var i=1e7; while(i--); })()'

real 0m0.043s
user 0m0.036s
sys 0m0.006s

Cheers,
--
Jorge.

Jorge

unread,
May 25, 2012, 10:55:56 AM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 3:01 PM, mscdex wrote:

> Is this tried with node master branch or node 0.6.x?

$ node -v
v0.6.6

--
Jorge.

Arnout Kazemier

unread,
May 25, 2012, 10:58:59 AM5/25/12
to nod...@googlegroups.com
I would rather say, have you tested it agains the latest version of v8..

On Friday 25 May 2012 at 15:01, mscdex wrote:

Is this tried with node master branch or node 0.6.x?

Jorge

unread,
May 25, 2012, 11:14:28 AM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 4:58 PM, Arnout Kazemier wrote:

> I would rather say, have you tested it agains the latest version of v8..

It's the latest v8: <https://github.com/v8/v8/tree/3.9>

$ node -e 'console.log(process.versions)'
{ node: '0.6.6',
v8: '3.9.24.29',
ares: '1.7.5-DEV',
uv: '0.6',
openssl: '0.9.8l' }


$ time node -e '(function() { var i=1e7; while(i--); })()'

real 0m0.092s
user 0m0.077s
sys 0m0.012s

$ time jsc -e '(function() { var i=1e7; while(i--); })()'

real 0m0.044s
user 0m0.036s
sys 0m0.007s

$ time node -e 'i=1e7; while(i--);'

real 0m1.950s
user 0m1.936s
sys 0m0.017s

$ time jsc -e 'i=1e7; while(i--);'

real 0m0.049s
user 0m0.042s
sys 0m0.007s

--
Jorge.

Jorge

unread,
May 25, 2012, 11:17:35 AM5/25/12
to nod...@googlegroups.com
Houston, there's a problem:

$ time node -e 'var i=1e7; while(i--);'

real 0m3.259s
user 0m3.245s
sys 0m0.021s

:-/
--
Jorge.

Arnout Kazemier

unread,
May 25, 2012, 11:26:53 AM5/25/12
to nod...@googlegroups.com

Jorge

unread,
May 25, 2012, 11:38:28 AM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 5:26 PM, Arnout Kazemier wrote:

> I was referring to https://github.com/v8/v8/tree/bleeding_edge

Thanks but no, thanks. I'm not going to install that yet... :-P

And, the jsc I've got isn't the latest version either.

Cheers,
--
Jorge.

Nathan Rajlich

unread,
May 25, 2012, 11:42:43 AM5/25/12
to nod...@googlegroups.com
I'm confused what point you're trying to make...

--
Jorge.

mscdex

unread,
May 25, 2012, 11:43:13 AM5/25/12
to nodejs
On May 25, 11:38 am, Jorge <jo...@jorgechamorro.com> wrote:
> On May 25, 2012, at 5:26 PM, Arnout Kazemier wrote:
>
> > I was referring tohttps://github.com/v8/v8/tree/bleeding_edge
>
> Thanks but no, thanks. I'm not going to install that yet... :-P

I'd at least try latest v8 3.10.x. I know it had some performance
increases that may be relevant to this particular test (I'm thinking
of the fix that came out of the threads_a_gogo thread).

Jorge

unread,
May 25, 2012, 11:50:13 AM5/25/12
to nod...@googlegroups.com
I'll try that, but IIRC that cocktail made node crash, isn't it?

Cheers,
--
Jorge.

mscdex

unread,
May 25, 2012, 12:06:54 PM5/25/12
to nodejs
On May 25, 11:50 am, Jorge <jo...@jorgechamorro.com> wrote:
> I'll try that, but IIRC that cocktail made node crash, isn't it?

I'm not entirely sure of the cause of that, but I believe node master
actually has v8 3.11.x right now and seems to work fine?

Jorge

unread,
May 25, 2012, 12:08:07 PM5/25/12
to nod...@googlegroups.com
With <https://github.com/v8/v8/zipball/3.10>

$ node -e 'console.log(process.versions)'
{ node: '0.6.6',
v8: '3.10.8.4',
ares: '1.7.5-DEV',
uv: '0.6',
openssl: '0.9.8l' }
Segmentation fault // to begin with... :-P

$ time node -e 'var i=1e7; while(i--);'
Segmentation fault // cool

real 0m3.525s
user 0m3.131s
sys 0m0.020s

$ time jsc -e 'var i=1e7; while(i--);'

real 0m0.050s
user 0m0.042s
sys 0m0.007s

$ time node -e '(function() { var i=1e7; while(i--); })()'
Segmentation fault // very well

real 0m0.389s
user 0m0.042s
sys 0m0.012s

$ time jsc -e '(function() { var i=1e7; while(i--); })()'

real 0m0.044s
user 0m0.036s
sys 0m0.007s

$ time node -e '0'
Segmentation fault // awesome

real 0m0.363s
user 0m0.026s
sys 0m0.011s

$ time jsc -e '0'

real 0m0.012s
user 0m0.005s
sys 0m0.006s

So: to graft a v8 3.10.8.4 into a node 0.6.6 is rather futile...
--
Jorge.

Jorge

unread,
May 25, 2012, 12:09:08 PM5/25/12
to nod...@googlegroups.com
> On May 25, 2012, at 5:42 PM, Nathan Rajlich wrote
>> On Fri, May 25, 2012 at 8:38 AM, Jorge <jo...@jorgechamorro.com> wrote:
>>> On May 25, 2012, at 5:26 PM, Arnout Kazemier wrote:
>>>
>>> I was referring to https://github.com/v8/v8/tree/bleeding_edge
>>
>> Thanks but no, thanks. I'm not going to install that yet... :-P
>>
>> And, the jsc I've got isn't the latest version either.
>
> I'm confused what point you're trying to make...

That v8 isn't (always) the speed champion as everybody seems to believe...
--
Jorge.

Bradley Meck

unread,
May 25, 2012, 2:02:55 PM5/25/12
to nod...@googlegroups.com
It may not be the speed champion, but its the API champion. For example Chakra in IE is stupid good at GC and Code-Gen speed (time to generate rather than run speed).

Arnout Kazemier

unread,
May 25, 2012, 2:11:21 PM5/25/12
to nod...@googlegroups.com
plain old jsc from OSX:

jsc -e '(function() { var i=1e7; while(i--); })()'  
0,03s user 0,00s system 90% cpu 0,034 total

plain old v8, freshly build from unstable:

./shell -e '(function() { var i=1e7; while(i--); })()'
0,02s user 0,00s system 88% cpu 0,023 total

So now we have fair tests, JS engine vs JS engine without any
node.js boot up code on top of..

But do we really care? Nope, because nobody writes code like this.

Jorge

unread,
May 25, 2012, 3:33:25 PM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 8:11 PM, Arnout Kazemier wrote:

> plain old jsc from OSX:
>
> jsc -e '(function() { var i=1e7; while(i--); })()'
> 0,03s user 0,00s system 90% cpu 0,034 total
>
> plain old v8, freshly build from unstable:
>
> ./shell -e '(function() { var i=1e7; while(i--); })()'
> 0,02s user 0,00s system 88% cpu 0,023 total
>
> So now we have fair tests, JS engine vs JS engine without any
> node.js boot up code on top of..
>
> But do we really care? Nope, because nobody writes code like this.

Yeah, right, but this is a bug of the (supposedly) speed champion:

$ time ./shell -e 'var i=1e7; while(i--);'
real 0m3.027s
user 0m2.949s
sys 0m0.027s

Or not?
--
Jorge.

Arnout Kazemier

unread,
May 25, 2012, 3:35:37 PM5/25/12
to nod...@googlegroups.com
Nope:

./shell -e 'var i=1e7; while(i--);'

0,03s user 0,00s system 91% cpu 0,042 total

jsc -e 'var i=1e7; while(i--);'

0,03s user 0,00s system 60% cpu 0,059 total

Jorge

unread,
May 25, 2012, 3:42:03 PM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 9:35 PM, Arnout Kazemier wrote:

> Nope:
>
> ./shell -e 'var i=1e7; while(i--);'
>
> 0,03s user 0,00s system 91% cpu 0,042 total
>
> jsc -e 'var i=1e7; while(i--);'
>
> 0,03s user 0,00s system 60% cpu 0,059 total


Don't you use loops in your programs? Yes. And what does it give you with node? 3 seconds. That's a bug.
--
Jorge.

Oliver Leics

unread,
May 25, 2012, 3:43:45 PM5/25/12
to nod...@googlegroups.com
Startup time is not a bug

You guys are funny
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en



--
Oliver Leics @ G+
https://plus.google.com/112912441146721682527

Jorge

unread,
May 25, 2012, 3:50:02 PM5/25/12
to nod...@googlegroups.com
It does not take 3 seconds to start it up.

Jorge

unread,
May 25, 2012, 3:50:37 PM5/25/12
to nod...@googlegroups.com
On May 25, 2012, at 8:02 PM, Bradley Meck wrote:

> It may not be the speed champion, but its the API champion. For example Chakra in IE is stupid good at GC and Code-Gen speed (time to generate rather than run speed).

Yes, the API is great. And it's easy(er) to build and embed than say, JSC or spidermonkey, and comes with (some) documentation, and it's what node uses (and we love node).

But it's taking over 3 seconds to run a loop, and that's not right. Clearly.
--
Jorge.

Bradley Meck

unread,
May 25, 2012, 4:25:09 PM5/25/12
to nod...@googlegroups.com
Agreed that the optimizations are kinda wonky with crankshaft / hydrogen etc. I wonder if more insight could be shown, or if there was a way to test it without the crankshaft / hydrogen anymore. JSC though is just as competitive more most tasks, in some better, in some the same, in some not. However, the 99% of people are probably not going to peg CPU, but this does make me think again about worker pools (god bless .fork and sending handles).

Oliver Leics

unread,
May 25, 2012, 5:21:27 PM5/25/12
to nod...@googlegroups.com
On Fri, May 25, 2012 at 9:50 PM, Jorge <jo...@jorgechamorro.com> wrote:
> It does not take 3 seconds to start it up.

then i don't understand the numbers and teh method.

Please explain:

$ time node -e 'i=1e7; while(i--);'

real 0m2.029s
user 0m2.008s
sys 0m0.016s

Those 2.029s really exclude startup time?

The 'time' command itself excludes them?

Jorge

unread,
May 25, 2012, 6:20:09 PM5/25/12
to nod...@googlegroups.com
The time it takes to start up is ~ that of a `time node -e ''`:

$ time node -e ''

real 0m0.044s
user 0m0.027s
sys 0m0.014s

--
Jorge.

Ben Noordhuis

unread,
May 25, 2012, 6:25:16 PM5/25/12
to nod...@googlegroups.com
On Fri, May 25, 2012 at 9:50 PM, Jorge <jo...@jorgechamorro.com> wrote:
Yes, that's probably a bug. Why don't you report it to the V8 team?

/thread

Nathan Rajlich

unread,
May 25, 2012, 7:35:19 PM5/25/12
to nod...@googlegroups.com
Jorge, what confuses me is that you're pointing out the same bug that you discovered in another thread from a while back (when you were claiming that your threads beat vanilla node). mraleph quickly discovered and fixed the bug, IIRC.

So still, I don't know what point you're trying to make...

Jorge

unread,
May 25, 2012, 8:00:30 PM5/25/12
to nod...@googlegroups.com
On May 26, 2012, at 1:35 AM, Nathan Rajlich wrote:

> Jorge, what confuses me is that you're pointing out the same bug that you discovered in another thread from a while back (when you were claiming that your threads beat vanilla node). mraleph quickly discovered and fixed the bug, IIRC.
>
> So still, I don't know what point you're trying to make...

Nathan, in the thread "When threads_a_gogo (*) beats node 2 to 1" a thread_a_gogo was 2x times faster that node's main thread, but now, here, what we're seeing is that Apple's jsc is running that über-simple loop ~ 50x faster than node! Even after applying Egorov's patch, node would still be 25x slower, and that's worrying (IMO), isn't it?

(*)https://github.com/xk/node-threads-a-gogo
--
Jorge.

Matt

unread,
May 25, 2012, 9:36:14 PM5/25/12
to nod...@googlegroups.com
No because that code wasn't the same code AT ALL.

Clearly there's a missing optimisation step in the current node - not a de-facto 2x speedup, but a way of running code that would miss the optimiser completely, possibly resulting in pathological cases in a 25x slowdown for all we know. Clearly that has been fixed in V8, given other people's benchmarks of "./shell". Have you actually run ./shell from bleeding_edge to test this against? Other people appear to have and demonstrate that your pathological case has been fixed.

Matt.

Jorge

unread,
May 26, 2012, 11:18:02 AM5/26/12
to nod...@googlegroups.com
Perhaps, we'll see.

In any case I just wanted to say it so here's this thread for reference and JFYI: 2957/49 == 60x times slower.

$ time node -e 'var i=1e7; while(i--);'

real 0m2.957s
user 0m2.942s
sys 0m0.023s

$ time jsc -e 'var i=1e7; while(i--);'

real 0m0.049s
user 0m0.042s
sys 0m0.006s

--
Jorge.

Bert Belder

unread,
May 26, 2012, 11:26:33 AM5/26/12
to nodejs
On May 25, 11:21 pm, Oliver Leics <oliver.le...@gmail.com> wrote:
> On Fri, May 25, 2012 at 9:50 PM, Jorge <jo...@jorgechamorro.com> wrote:
> > It does not take 3 seconds to start it up.
>
> then i don't understand the numbers and teh method.
>
> Please explain:
>
>   $ time node -e 'i=1e7; while(i--);'
>
>   real    0m2.029s
>   user    0m2.008s
>   sys     0m0.016s
>
> Those 2.029s really exclude startup time?
>
> The 'time' command itself excludes them?

Startup time should be in the order of 10s of milliseconds, so that's
not it. However, there's a simple explanation for it.
First of all, notice that `node -e` uses `eval()` (see
https://github.com/joyent/node/blob/82bcdbb8aaa4cf58917dc8d3fd4fcfc272512a2c/src/node.js#L264).

* node -e "var i=1e7;while(i--);"
This defines a new local variable in the context of the function that
called eval, unless there already was one there. v8 cannot optimize
functions where the scope of variables can be changed dynamically; it
can only optimize when it can statically determine whether a variable
is a local, or closure scoped, or a global object property.

* node -e "(function test() { var i=1e7;while(i--); })()"
This doesn't get optimized, but since v8 is certain that `var i` is a
local here, the generated code is reasonably efficient anyway.

* echo "i=1e7;while(i--);" > test.js && node test.js
`i` is a global variable here. Global variables are slow in non-
optimized code, but since no weird scope resolution corner cases are
present, v8 is able to detect that this is a 'hot' function and
optimize it. Hence, it is also reasonably fast.

* echo "var i=1e7;while(i--);" > test.js && node test.js
This is probably as fast as it gets, since it is both optimizable and
`var i` is a local.

The fact that node uses eval() might be considered a bug. However it
is highly unlikely that it will make your programs slow, since you
won't be running it with `node -e`.

(And I am sort of disappointed that the thread starter didn't figure
it out himself - I mean, it's like 20 seconds work to put the
offending code in a .js file and figure out that it's not slow at all.
It looks a lot like "sensationalist benchmarking" to me.)

- Bert

Oliver Leics

unread,
May 26, 2012, 12:01:05 PM5/26/12
to nod...@googlegroups.com
On Sat, May 26, 2012 at 5:26 PM, Bert Belder <bertb...@gmail.com> wrote:
> On May 25, 11:21 pm, Oliver Leics <oliver.le...@gmail.com> wrote:
>> On Fri, May 25, 2012 at 9:50 PM, Jorge <jo...@jorgechamorro.com> wrote:
>> > It does not take 3 seconds to start it up.
>>
>> Please explain:
>>
>>   $ time node -e 'i=1e7; while(i--);'
>>
>
> Startup time should be in the order of 10s of milliseconds, so that's
> not it. However, there's a simple explanation for it.
> First of all, notice that `node -e` uses `eval()` (see
> [...]

Thank you.

@Jorge

Please post the numbers for

echo "var i=1e7;while(i--);" > test.js && time node test.js

and

echo "var i=1e7;while(i--);" > test.js && time jsc test.js

Thank you in advance.

- o

Vyacheslav Egorov

unread,
May 26, 2012, 12:18:05 PM5/26/12
to nod...@googlegroups.com
Just do:

./shell -e 'var s = Date.now(); var i=1e7; while(i--); print(Date.now() - s);'
./jsc -e 'var s = Date.now(); var i=1e7; while(i--); print(Date.now() - s);'

This way we will see the cost of setting up/tearing down VM vs. the
cost of running loop.

(also ensure that your node/shell is compiled with snapshots
(snapshot=on) so at least Context boostrapping time is not included).

Then if you still can repro: specify all details of your build (OS,
architecture, hardware vs. virtualized env etc).

Also ensure that shell and jsc are of the same arch (file shell, file jsc).


--
Vyacheslav Egorov

Jorge

unread,
May 26, 2012, 2:48:34 PM5/26/12
to nod...@googlegroups.com
Yes, this is much better:

$ time node <<EOF
var i= 1e7;
while (i--);
EOF

real 0m0.116s
user 0m0.091s
sys 0m0.013s

$ time echo 'var i= 1e7; while(i--);' | node

real 0m0.069s
user 0m0.052s
sys 0m0.015s

$ time jsc <<EOF
var i= 1e7;
while (i--);
i;
EOF
-1

real 0m0.050s
user 0m0.042s
sys 0m0.008s

Though still worse than jsc.

> The fact that node uses eval() might be considered a bug. However it
> is highly unlikely that it will make your programs slow, since you
> won't be running it with `node -e`.

Perhaps you should add a note about this somewhere in the docs.
Perhaps the risk of suffering such a slowdown deserves it.

> (And I am sort of disappointed that the thread starter didn't figure
> it out himself - I mean, it's like 20 seconds work to put the
> offending code in a .js file and figure out that it's not slow at all.
> It looks a lot like "sensationalist benchmarking" to me.)

I just wanted to share what I discovered so that the experts like you could dig in further.

Thanks,
--
Jorge.

Jorge

unread,
May 26, 2012, 2:54:26 PM5/26/12
to nod...@googlegroups.com
$ echo "var i= 1e7; while(i--);" > test.js && time node test.js

real 0m0.074s
user 0m0.051s
sys 0m0.011s

$ echo "var i= 1e7; while(i--);" > test.js && time jsc test.js

real 0m0.047s
user 0m0.041s
sys 0m0.005s
--
Jorge.

Bert Belder

unread,
May 26, 2012, 3:38:41 PM5/26/12
to nodejs
Well, here the startup time *does* matter. In fact, I think that
startup time is the only cause of the observed time difference.

- Bert
Reply all
Reply to author
Forward
0 new messages