[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: =~ vs match - Some benchmarks.

Antonio Cangiano

12/21/2005 5:37:00 PM

John Carter wrote:
> While profiling some code I noticed =~, String.match and Regexp.match
> turning up in my hotspots. So here is the results of a little
> benchmarking to resolve which is faster to use... {cut}

> Results on a P4 2.66Ghz using ruby-1.8.3...
>
> string='as fun as looking for frogs in custard'
> regex=(?-mix:frogs)
> user system total real
> string=~/frogs/o 4.390000 1.170000 5.560000 ( 5.936591)
> string=~/frogs/ 4.390000 1.160000 5.550000 ( 6.922374)
> string=~/#{toad}/o 4.450000 1.130000 5.580000 ( 7.111464)
> string=~regex 4.850000 1.100000 5.950000 ( 8.030837)
> regex=~string 4.690000 1.150000 5.840000 ( 7.055707)
> string=~regexo 5.000000 1.120000 6.120000 ( 6.471198)
> string=~/#{toad}/ 23.750000 1.290000 25.040000 ( 28.654952)
> regex.match 7.180000 1.180000 8.360000 ( 9.444980)
> string.match 7.950000 1.170000 9.120000 ( 9.726876){cut}

Interesting test, John. :)
My results on a P4 1.8Ghz using ruby-1.8.2 on Linux:

string='as fun as looking for frogs in custard'
regex=(?-mix:frogs)
user system total real
string=~/frogs/o 3.650000 0.000000 3.650000 ( 3.683330)
string=~/frogs/ 3.520000 0.010000 3.530000 ( 3.560874)
string=~/#{toad}/o 3.520000 0.010000 3.530000 ( 3.612038)
string=~regex 4.110000 0.000000 4.110000 ( 4.159460)
regex=~string 3.970000 0.010000 3.980000 ( 4.009281)
string=~regexo 4.010000 0.010000 4.020000 ( 4.046814)
string=~/#{toad}/ 29.650000 0.150000 29.800000 ( 30.071113)
regex.match 6.920000 0.030000 6.950000 ( 7.015763)
string.match 8.230000 0.210000 8.440000 ( 8.739469)

Antonio