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
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.