News for hackers. Stuff that matters.
Re:ClojureScript and optimized C [video] by mpweiher on Monday November 28, 2016 @02:03PM (#13057572)
I think the problem is that it's using doubles, which JavaScript VMs feel free to optimise to ints. If I change the C code to long, I get the following:

   marcel@sarek[tmp]cc -Os sumints.c && ./a.out 
   49999995000000
    Elapsed time: 0.000031 millis
The original:

   marcel@sarek[tmp]cc -Os orig.c && ./a.out 
   49999995000000
   Elapsed time: 8.276664 millis
That's a factor 266989 difference, if anyone cares :)
Re:ClojureScript and optimized C [video] by jjnoakes on Monday November 28, 2016 @02:35PM (#13057773)
Can you post your code, compiler, and the disassembly from main()? The only way I believe these numbers is if your compiler optimized the loop away to a constant.
Re:ClojureScript and optimized C [video] by mpweiher on Monday November 28, 2016 @03:34PM (#13058163)
That's exactly what it (clang) did.
Re:ClojureScript and optimized C [video] by jjnoakes on Monday November 28, 2016 @03:47PM (#13058267)
You should update your YouTube comment too :)
Re:ClojureScript and optimized C [video] by mwkaufma on Monday November 28, 2016 @02:33PM (#13057769)
Correct me if I'm wrong, but this is basically just timing how fast we can read and write to a single CPU register, so it's eliding all the memory bottlenecks that actually surface performance differences between native hotloops and JITed code.
Re:ClojureScript and optimized C [video] by yegortimoshenko on Monday November 28, 2016 @12:09PM (#13056757)
Clojure on JVM is about 80x slower than ClojureScript in this scenario, by the way.
Re:ClojureScript and optimized C [video] by sooheon on Monday November 28, 2016 @01:40PM (#13057421)
So Javascript compilers are faster than Java now?
Re:ClojureScript and optimized C [video] by sdegutis on Monday November 28, 2016 @01:48PM (#13057478)
Not really.

The code in question:

    (apply + (range 1e7))
is just summing a bunch of numbers. That's it. It's very easy to optimize for the sake of benchmarks.

It's way too trivial to use for any kind of meaningful real-world comparison.

Re:ClojureScript and optimized C [video] by bad_user on Monday November 28, 2016 @05:23PM (#13058945)
I'm working on a cross-compiled library and I am able to compare the same code compiled for the JVM and for Javascript, the language used being Scala, which targets the JVM as a primary target and now we also have http://scala-js.org which is quite good btw.

I can tell you that the answer is definitely no, in my tests V8 being slower than the JVM by a factor ranging between 4 and 10.

If you're interested in seeing that in action, you can download the library's source code and run its tests for the JVM and see how that feels in comparison with the same tests being executed for JS. See: https://github.com/monix/monix

Re:ClojureScript and optimized C [video] by fermigier on Monday November 28, 2016 @02:21PM (#13057677)
On my machine (2 yo MacBookPro), I get ~7 msec for the C version, 10 ms for PyPy, 35ms for CLJS, 240ms for Python 3.5, 300 ms for Python 2.7.
Re:ClojureScript and optimized C [video] by gus_massa on Monday November 28, 2016 @11:40AM (#13056517)
Nice comparison. Do you have a text version of the same benchmark?

[PS: Next time remember to submit the youtube.com version instead of the youtu.be, because youtu.be is autokilled.]

Re:ClojureScript and optimized C [video] by mfikes on Monday November 28, 2016 @01:16PM (#13057261)
Re:ClojureScript and optimized C [video] by fermigier on Monday November 28, 2016 @02:02PM (#13057567)
The more I run the CLJS script, the longer it takes:

https://gist.github.com/sfermigier/9f60f01d1b4e8508a3a56bc42...

Any idea why ?

Re:ClojureScript and optimized C [video] by verandaguy on Monday November 28, 2016 @02:15PM (#13057642)
Probably just the parser getting tired.

In seriousness -- does this behaviour persist if you drop the computation into a `for` loop for a number of iterations instead of calling it manually every time?

Re:ClojureScript and optimized C [video] by bpicolo on Tuesday November 29, 2016 @12:48AM (#13061136)
I wonder if it's re-evaluating the previous statements up to that juncture each time, though that would be easy to test probs.