Re: Strange benchmark result for Phix vs Eu 3.1.1
- Posted by petelomax Aug 21, 2017
- 1263 views
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.
In case you didn't know (though I expect you did), the actual definition for sq_rand is in builtins\psqop.e:
global function sq_rand(object a) if atom(a) then return rand(a) end if for i=1 to length(a) do a[i] = sq_rand(a[i]) end for return a end function
Is this related to the other discussion on function calling?
Yes, with another little bugbear: after/with s[i] = <tmp>, the compiler should somehow mark <tmp> as unassigned/zero (since it then is), and not need to test/decref/deallocate it, but it don't...
Anyway, modifying builtins/psqop.e to:
global function sq_rand(object a) if atom(a) then return rand(a) end if for i=1 to length(a) do -- a[i] = sq_rand(a[i]) object ai = a[i] ai = iff(atom(ai)?rand(ai):sq_rand(ai)) a[i] = ai end for return a end function
Then I get RDS Eu (2.4): 3.40s, Phix: 3.48s
Putting a[i] = ai on a separate line allows the nested call to use pbr, otherwise it would double-up on that test/decref/deallocate bugbear (which is still there, not that you could legally remove it for a named temp, ai in this case).
I'll make that change for the next release, to solve this specific problem, but yes, there's room for some more general improvement, somehow.
Regards,
Pete