Strange benchmark result for Phix vs Eu 3.1.1
- Posted by lesterb Aug 21, 2017
- 1326 views
I was messing about with file benchmarks and came across a case where Phix is much slower than Eu 3.1. The benchmark requires 100 files to be created on disk, with each file containing 1000000 random bytes. The program for Eu is...
constant BUFFER_SIZE = 10000, SizeOfFile = 1000000, FilesToWrite = 100, randbuff = repeat(255, BUFFER_SIZE) integer cnt, fptr, blen atom tend, tstart tstart = time() for NFiles = 1 to FilesToWrite do fptr = open(sprintf("f%d.dum", NFiles), "wb") cnt = SizeOfFile blen = BUFFER_SIZE while cnt > 0 do if cnt < blen then blen = cnt end if puts(fptr, rand(randbuff[1..blen])) -- EU -- puts(fptr, sq_rand(randbuff[1..blen])) -- PHIX cnt -= blen end while close(fptr) end for tend = time() printf(1, "Execution time = %3.2f\n", tend - tstart)
On my setup with Eu 3.1.1, this runs in about 5 sec. Very reasonable. With Phix 0.7.6 (change the rand call to sq_rand) it takes almost 13 sec. I have verified that it's the sq_rand call that makes the big difference by removing all the file stuff and just generating random data.
The sawn-off Eu benchmark code is...
constant BUFFER_SIZE = 10000, SizeOfFile = 1000000, FilesToWrite = 100, randbuff = repeat(255, BUFFER_SIZE) integer cnt, blen atom tend, tstart sequence p tstart = time() for NFiles = 1 to FilesToWrite do cnt = SizeOfFile blen = BUFFER_SIZE while cnt > 0 do if cnt < blen then blen = cnt end if p = rand(randbuff[1..blen]) -- EU -- p = sq_rand(randbuff[1..blen]) -- PHIX cnt -= blen end while end for tend = time() printf(1, "Execution time = %3.2f\n", tend - tstart)
The timings are now Eu: 4.5 sec, Phix: 12.4 sec.
Since I know in this case that the random buffer has no nested sequences, I wrote my own function which avoids the nested call to sq_rand as follows...
function bsq_rand(object a) for i = 1 to length(a) do a[i] = rand(a[i]) end for return a end function
Using bsq_rand instead of sq_rand in the code above gives Phix: 4.21 sec.
So I know how to improve the Phix benchmark result but it surprised me how big the difference in time is.
Is this related to the other discussion on function calling?