forum-msg-id-128414-edit
Original date:2015-07-27 00:18:51 Edited by: Spock Subject: Re: better flatten()?
I decided it was about time I added flatten() to Phix, so I had a look at the one in std\sequence.e
... after staring at it incredulously for a while.. I decided it was utter shite, so I wrote my own. Not entirely surprisingly ... it ran between 50 and 250 times faster.
Does anyone want to check that this does what the docs say it should and is indeed significantly faster?
The results on Phix varied depending on which level of repeat had 1000, whereas on eui (a somewhat dated r3412) it was about 25 times faster wherever the 1000 was.
...
Pete
EDIT: I just spotted that neither flatten nor flatten2() pass delim when making their recursive calls - should they?
Pete, I get results similar to yours using a simplified version (in Orac, that don't quite get the last delimiter right..anyway). I think the delimiter should be passed in the recursion otherwise it is just emitted at the top-level which implies the author could only imagine a nested structure with a few fixed levels - quite bizarre for Euphoria.
On the last test my code is faster than flatten() by a factor of 2654 times..
Thank you. For the umpteenth time it highlights why I hardly ever bother with \std
Spock
function flattenX(seq s, obj delim="") -- init seq ret = "" -- loop for i = 1 to ~ s do obj x = s.i if atom(x) then ret &= x & delim else ret &= flattenX( x, delim ) end if end for -- exit return ret end function
Not Categorized, Please Help
|