News for hackers. Stuff that matters.
Re:Yet Another Language Speed Test – Counting Primes by ryanmk on Friday July 03, 2015 @11:23PM (#9829015)
It would be nice to see the numbers, in addition to the graph.

I did a straight port of C to lua, and ran it with luajit.

The C code ran in 49.901s.

The luajit code ran in 14m16.547s.

C code was compiled with -02 -std=c11 -lm (version 4.8.1, mingw).

luajit.exe was 2.0.3, static build, using VS2012 x64

Re:Yet Another Language Speed Test – Counting Primes by userbinator on Friday July 03, 2015 @11:32PM (#9829045)
It would also be nice to express numbers in the same base too. :-)

"The luajit code ran in 856.547s."

The graph is log-log which can be a bit tricky to read but that puts it in the same ballpark as Ruby and PHP (assuming the same factor of difference between the two, after scaling your C vs luajit results to match the given C value of ~40s, luajit becomes 687s.)

Re:Yet Another Language Speed Test – Counting Primes by whoopdedo on Saturday July 04, 2015 @12:32AM (#9829214)
Did you turn off the JIT? My LuaJIT ran 2.16x slower versus 8x for Lua 5.1, 9.35x 5.2, 10.33 5.3. (I didn't localize the math.sqrt but I know LuaJIT wouldn't care.)

* Oops, I had cheated and used a for loop instead of while. The LuaJIT time was the same but the others are 10.5x, 12.58x, 15.63x.

Re:Yet Another Language Speed Test – Counting Primes by letitgo12345 on Saturday July 04, 2015 @12:28AM (#9829199)
On OSX 10.1 with luajit 2.1.0 alpha, a straight translation of the C code gets me 59 seconds on my machine which is close to the C speed on it (38 seconds compiled with O3)

Edit: fixed luajit version

Re:Yet Another Language Speed Test – Counting Primes by ryanmk on Saturday July 04, 2015 @01:23AM (#9829329)
I've placed my port here: https://gist.github.com/anonymous/ce176d7ab4f6b7b1ba91

If you see anything wrong with it, or odd, feel free to share.

I'm still investigating what is happening to make the run so slow, so if you can find something wrong in my code, that would help.

Re:Yet Another Language Speed Test – Counting Primes by whoopdedo on Saturday July 04, 2015 @04:49AM (#9829667)
Lua is global by default. Declare all the variables as local and you'll see significant improvement. Also, there is a boolean type so you can use true and false directly instead of comparing numbers.
Re:Yet Another Language Speed Test – Counting Primes by ryanmk on Saturday July 04, 2015 @01:40PM (#9830874)
I tried using locals, and there was no change to the time. Using a boolean return value for isPrime shaved off two seconds.
Re:Yet Another Language Speed Test – Counting Primes by deegu on Saturday July 04, 2015 @04:02AM (#9829599)
if you run it with luajit -jv primes.lua you'll see NYIs about math.mod not implemented.

Replacing math.mod(n, i) with (n % i) gives roughly 9.4x performance.

EDIT: luajit version was LuaJIT 2.0.4 on Mac OSX

Re:Yet Another Language Speed Test – Counting Primes by ryanmk on Saturday July 04, 2015 @01:30PM (#9830836)
Thanks, using % did the trick.