1. Pi Benchmark Game
- Posted by _tom (admin) Aug 23, 2018
- 1818 views
In the Can OpenEuphoria Help Solve This? topic I had a messy start on a PI calculation benchmark. Thanks to Pete I can present better benchmarks:
Comparing the fastest interpreters: OE, Phix, and LuaJIT.
Testing on a 32bit atom netbook.
Language | Time in Seconds |
---|---|
OE Interpreter | 10 |
OE Compiled | 2.1 |
Phix Interpreter | 6 |
Phix Compiled | 4.7 |
LuaJIT Interpreter | 17 |
Testing on a 64bit i5 netbook:
Language | Time in Seconds |
---|---|
OE Interpreter | 3.1 |
OE Compiled | 0.25 |
Phix Interpreter | 1.4 |
Phix Compiled | 1.3 |
LuaJIT Interpreter | 2.5 |
The source-code for this test is at the wiki page https://openeuphoria.org/wiki/view/Calculate%20Pi.wc
_tom
2. Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1804 views
Sorry, but are you sure you're using Luajit and not the standard Lua interpreter?
3. Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1798 views
To use LuaJIT you need to install it separately and call "luajit" instead of "lua". Sorry, but your numbers don't make any sense. LuaJIT slower than interpreted OE and interpreted Phix? Not possible.
4. Re: Pi Benchmark Game
- Posted by _tom (admin) Aug 23, 2018
- 1807 views
To use LuaJIT you need to install it separately and call "luajit" instead of "lua". Sorry, but your numbers don't make any sense. LuaJIT slower than interpreted OE and interpreted Phix? Not possible.
I do not have any Lua installation, only LuaJIT.
For the 32bit atom, Bodhi Linux:
$ luajit LuaJIT 2.0.5 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/ JIT: ON CMOV SSE2 SSE3 ATOM fold cse dce fwd dse narrow loop abc sink fuse >
For the 64bit i5, Mint Linux:
$ luajit LuaJIT 2.0.5 --Copyright (C) 2005-2017 Mike Pall. http://luajit.org/ JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse >
Where do I look next?
_tom
5. Re: Pi Benchmark Game
- Posted by irv Aug 23, 2018
- 1782 views
EUI: 2.290000 EUC: 0.820000 LUAJIT: 2.960000
This is on an (old) Intel Quad 2.33 ghz with 8g memory (64bitz) No Lua on this computer.
6. Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1793 views
This is really strange. I don't understand why on my machine LuaJIT is 10x faster than compiled Euphoria and 20x faster than interpreted Euphoria, while on yours it's the opposite. I hope that someone knows why and will explain it to me.
7. Re: Pi Benchmark Game
- Posted by irv Aug 23, 2018
- 1803 views
This is really strange. I don't understand why on my machine LuaJIT is 10x faster than compiled Euphoria and 20x faster than interpreted Euphoria, while on yours it's the opposite. I hope that someone knows why and will explain it to me.
You may wish to be sure all programs are generating PI to the same 2400 digits. PI in all cases should end with ...602850
8. Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1868 views
OK. Please, run this code. It calculates 10000 digits of PI.
Euphoria:
include std/math.e include std/text.e atom n = 35001, a = 10000, d, g, k, e = 0 sequence f = repeat(2000, n) for c = n to 14 by -14 do d = 0 for b = c to 1 by -1 do d = d * b g = b * 2 - 1 d = d + f[b] * a f[b] = mod(d, g) d = floor(d / g) k = e + floor(d / a) end for sequence k2 = "000000" & sprint(k) puts(1, k2[(length(k2) - 3)..(length(k2))]) e = mod(d, a) end for
Lua:
n, a, d, g, k, e = 35001, 10000, 0, 0, 0, 0 f = {} for x = 1, n do f[x] = 2000 end for c = n, 14, -14 do d = 0 for b = c, 1, -1 do d = d * b g = b * 2 - 1 d = d + f[b] * a f[b] = d % g d = math.floor(d / g) k = e + math.floor(d / a) end k2 = "000000" .. tostring(k) io.write(string.sub(k2, string.len(k2) - 3)) e = d % a end
As you can see, it's the same algorithm. On my machine Luajit takes 0m0.941s (less than one second) to calculate and print 10000 digits of PI, while interpreted Euphoria takes 24 sec.
9. Re: Pi Benchmark Game
- Posted by irv Aug 23, 2018
- 1776 views
Using those algorithms (worst case for Eu, best for Luajit):
first run, luajit was slower than compiled eu. running a second time, lua works better.
EUI: 13.210000 EUC: 2.560000 LUAJIT: 0.890000
11. Re: Pi Benchmark Game
- Posted by irv Aug 23, 2018
- 1733 views
OK. These numbers make sense.
Going back to the original code, but changing to 10000 digits:
EUI: 39.460000 EUC: 14.360000 LUAJIT: 51.620000
So, the choice of algorithm makes all the difference. It's always possible to choose one that runs slower (or faster) in one language than another.
For example, if you take out the needless creation of a new sequence for k2 every time thru the loop in your version:
EUI: 13.140000 EUC: 2.540000 LUAJIT: 0.900000
EUI: 13.090000 EUC: 2.160000 LUAJIT: 0.890000
12. Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1715 views
And what's interesting, in your example compiled Euphoria is just 2x faster than the interpreted one. This is max. I can get on my laptop. At last I think we are getting somewhere with these numbers.
13. Re: Pi Benchmark Game
- Posted by irv Aug 23, 2018
- 1712 views
In the first benchmark, in which LuaJIT did so poorly, it seems to be because it was swapping processors 5 or 6 times during the run, with a pause each time while it juggled memory or something. Eu uses just one processor for the job.
14. Re: Pi Benchmark Game
- Posted by Spock Aug 23, 2018
- 1718 views
OK. These numbers make sense.
Going back to the original code, but changing to 10000 digits:
EUI: 39.460000 EUC: 14.360000 LUAJIT: 51.620000
So, the choice of algorithm makes all the difference. It's always possible to choose one that runs slower (or faster) in one language than another.
For example, if you take out the needless creation of a new sequence for k2 every time thru the loop in your version:
EUI: 13.140000 EUC: 2.540000 LUAJIT: 0.900000
EUI: 13.090000 EUC: 2.160000 LUAJIT: 0.890000
Irv,
Changing the type to 'integer' and then compiling might also improve EUC. On my system it improved EUI from 8s to 7.5s
Spock