Good comments Christian. I thought I’d just hack a set of tests and
post some quick results, but all I think I did was prove that I’m not
supposed to be coding first thing in the morning.
Yes, once you fix that bug in the code by caching the Regexes, they
perform very impressively. In fact, for the modified tests I just ran,
they beat out every other solution in every case except for extremely
large league sizes (> 18,000 elements) where they wouldn’t run at all.
But I’m loathe to draw any conclusions from the data just yet. (Burned
once, twice shy?)
There appears to be at least one other bug in the code. One astute,
anonymous person pointed out that the six solutions will not return the
same results for the generated datasets and that preprocessing of input
data could help improve performance even more. I think it all depends
on how one defines the problem as to whether the generated data is
valid input or undefined requirements now being levied on the code.
Mmmm… I hope JEG II is watching this thread as I’m wondering if
there isn’t a rubyquiz in here somewhere.