From: Robert Klemme Date: 2007-08-07T14:15:08+09:00 Subject: Re: Determining the common prefix for several strings On 07.08.2007 03:16, Pe�a wrote: > From: Robert Klemme [mailto:shortcutter@googlemail.com] > # I have added some interesting benchmarking: > # > # $ ./prefix.rb > # user system total real > # 1000 * list.rx 0.016000 0.000000 0.016000 ( 0.014000) > # 1000 * list.rx with conversion 0.031000 0.000000 0.031000 ( 0.030000) > # 1 * large.rx 0.000000 0.000000 0.000000 ( 0.000000) > # 1 * large.rx with conversion 0.000000 0.000000 0.000000 ( 0.000000) > > Robert, thanks for the benchmark. I included Brian|Martin's solution in the mix but still the regex scheme is way a lot better w regards to speed. > > Could some kind soul enlighten me why the regex solution works better, and even best using large strings? My theory is that it's completely done in C and there is only *one* invocation. All other solutions need some form of iteration implemented in Ruby. Kind regards robert