r/programming • u/[deleted] • Oct 02 '15
A Language Speed Test on Embedded Linux boards
http://www.digitalpeer.com/blog/a-language-speed-test-comparing-embedded-linux-boards5
u/dreugeworst Oct 02 '15
Wow, really surprised by the javascript results there, did not expect it to be so close to c.
4
u/emn13 Oct 02 '15
Due to the poor scaling on those graphs it's pretty hard to see how close it really is. A logarithmic scale would have been a better choice.
However, I was surprised by the large startup penalty JS had compared to other scripting languages - that may mean it's the only JITted language on these boards?
2
u/NeuroXc Oct 02 '15
The only one in these tests anyway. All of the other languages (except C) do have JIT implementations but not with the default interpreters (pypy, JRuby, LuaJIT, and HHVM respectively are required).
1
u/digitalpeer Oct 03 '15
You are entirely correct. A logarithmic scale should have been used. Rookie mistake. Charts have been updated.
2
u/dchanman Oct 02 '15
Yeah I was surprised too. Do we know why that is?
13
Oct 02 '15
Because Google V8 has the most developed JIT of any of the languages represented, and because the test is entirely integer math. The JITted result is probably similar to the C code, but with a lot of extra checks to bail out of the fast path if the code starts doing something more dynamic.
It would be interesting to see how LuaJIT compares. I've heard it's also surprisingly close to C in speed.
1
Oct 02 '15
It might also be straight forward to translate the JS to asm.js, which could in turn give interesting results.
There was an article a while ago where Mozilla had asm.js end up running faster than compiled C, and almost as fast as when the code was optimized. All on a mobile device.
0
u/jringstad Oct 02 '15
It's odd though that it fares pretty well on some of the boards and poorly on others. I wonder if the JIT is disabled on those other boards.
1
u/matthieum Oct 02 '15
Could it be a matter of instruction set? Like, on some boards some instructions are missing that make the JIT fallback to a much less optimized scheme?
1
2
Oct 02 '15
Roughly twice as fast as the C implementation, but that's just because the C implementation checks divisibility of n for all odd numbers <= sqrt(n) instead of just primes <= sqrt(n).
0
Oct 02 '15
[deleted]
2
Oct 02 '15
if the C implementation is handycapped by poor implementation doesnt that explain to dchanman why the javascript results may have been so close to C (the question he was replying to)?
5
u/raluralu Oct 02 '15 edited Oct 02 '15
Can you try running python using pypy. ? Extra:
Can you test haskell please? All you need is ghc and command is
ghc -O2 source.hs
isPrime n
| n < 2 = False
| n == 2 = True
| n `mod` 2 == 0 = False
| otherwise = foldl (&&) True ( map ( \x -> (n `mod` x) /= 0) [3,5.. (floor $ sqrt $ fromIntegral n) ] )
main = print ( length ( filter isPrime [1 .. 2^24]))this code is identical with implementation as all other code (I could "cheat" and made faster and smarter algorithm, but here is not case)
3
u/digitalpeer Oct 02 '15
Interesting that you bring pypy up. I can tell you it is significantly faster with this test making it one of the fastest languages of the test. However, it was not immediately included because it is missing from buildroot. It will be some extra work to cross compile it for the different architectures. Haskell is another one I would personally like to see.
I'll see what I can do.
6
u/sacwtd Oct 02 '15
Kinda wanted to see c++ in there too..
2
u/ukalnins Oct 02 '15
It would basically be the same C code. There are just some ints and a function call. Why he didn't us -O3 though, is puzzling.
2
u/mydogkeepsbitingme Oct 02 '15
-O3 can make it faster, but also increases the executable size? Also, it's not always faster, I think.
10
u/NeuroXc Oct 02 '15
This. It's not always faster because it increases the executable size, which means a program that might fit in the CPU cache with -O2 might not fit with -O3.
1
u/digitalpeer Oct 02 '15
I ran and tested the code on a PC and I can tell you the difference between C and C++ are negligible for this specific test. C was included in these results as a good baseline.
1
u/sacwtd Oct 02 '15
Fair enough. I use c++ in one of my embedded Linux code bases, and while it never feels any slower than the c it replaced, I'm always curious.
0
Oct 02 '15
[deleted]
9
u/emn13 Oct 02 '15
If the aim is to compare languages, then algorithmic changes aren't helpful.
(Though due to the inclusion of at least some dynamically allocated data, your algorithm is a more interesting benchmark).
1
u/igouy Oct 02 '15
"This is not a test to optimize the languages, the code, or the boards to be as fast as possible. Instead it is intended to run the same exact code using the same runtime version of a language on different embedded Linux boards in as identical an environment as possible."
I guess that means the aim is to compare the boards.
3
u/digitalpeer Oct 02 '15
That was absolutely my point. As has been said though, once you start putting multiple languages on a chart they are going to be compared.
1
1
u/matthieum Oct 02 '15
I would rather think the aim is to compare the compilers/optimizers used.
It does of course does a disservice to languages which would make expressing a faster solution much easier than others...
1
u/igouy Oct 03 '15
I've quoted what the author tell's us about the aim, so why would you think that is not the aim!
3
2
2
u/yellowhat4 Oct 02 '15
I wonder how rust would perform
2
u/matthieum Oct 02 '15
In this case? Probably like C and C++. There's nothing exciting feature-wise.
Now, if it were a parallel implementation, things would be different.
2
2
u/kirbyfan64sos Oct 02 '15
I would've liked it if it also covered alternative interpreters like PyPy and LuaJIT.
2
u/Yojihito Oct 02 '15 edited Oct 02 '15
No Go and Rust? :(
I could write a multithreaded solution for Go (not perfect but good enough I hope), but seeing that the Raspberry Pi 2 was not much faster than the Raspberry Pi 1 it looks like they all are single threaded?
2
u/changtimwu Oct 02 '15
The same thoughts. In X86, GO programs utilizing go-routine can archive 130~200% performance boost when number of cores increases from 1 to 4.
https://docs.google.com/document/d/1At2Ls5_fhJQ59kDK2DFVhFu3g5mATSXqqV5QrxinasI/edit Besides, GO is the most cross-compilation friendly language among static PLs. To port a console program from OSX and ARM-Linux, all that I did is just assigning GOOS=linux GOARCH=arm to the go command. All dependent packages are automatically recompiled into ARM.1
3
1
u/deanfranks Oct 02 '15
As a comparison of the boards, the lack of threading in the benchmark makes it kind of useless for comparing the performance of the boards or the languages. Even though a lot of embedded apps are single threaded, there are often other things running on the board that take advantage of the other cores.
A real-world example of things that people actually do on embedded boards in the various languages would be more interesting.
1
0
u/skulgnome Oct 02 '15
Which camera takes the best pictures? Which car goes the fastest? Which martial art is the deadliest? Which language is the fastest?
0
u/jms_nh Oct 02 '15
dude, get rid of the sqrt; a < sqrt(n) is equivalent to a*a < n for positive numbers.
0
Oct 02 '15
[deleted]
1
u/jms_nh Oct 03 '15 edited Oct 03 '15
Then at least use a fast integer sqrt approximation.
Alternatively, use divmod (builtin in Python and Ruby, library function in C) instead of % to compute q,r where iq + r = n, and exit the loop when q >= i. The division is happening whether you use
/or%ordivmodand it's just a matter of where the results go.full-precision sqrt() is costly on an embedded processor, and most of the time isPrime only takes a few loop iterations, so, yeah, calculating it once at the beginning is cheap if the number in question is large and prime, but otherwise you take a hit on composite numbers.
0
Oct 03 '15
[deleted]
1
u/jms_nh Oct 03 '15
(Exit when q < i btw)
right, I got it backwards. I keep telling people when I have a choice between two alternatives I get it wrong about 60% of the time.
1
7
u/coder111 Oct 02 '15
I'll just leave this here.
http://benchmarksgame.alioth.debian.org/
OTOH digitalpeer guys ran the test on embedded boards- interesting comparison.