From: Ben Bleything Date: 2008-02-21T07:55:34+09:00 Subject: Re: IP Address to Decimal - inject sucks On Thu, Feb 21, 2008, Ryan Davis wrote: > Ara's pack/unpack is always what I intuitively reach for in a problem > like this, but it turns out to be more expensive than a simple map/ > left-shift form. IPAddr is very powerful, but there is a cost to that > power (parsing every IP form under the sun). If I needed anything more > than JUST converting to/from ints I'd use IPAddr. > > # of iterations = 100000 > user system total real > null_time 0.020000 0.000000 0.020000 ( 0.017184) > split/map/<<+ 1.040000 0.000000 1.040000 ( 1.042783) > split/map/pack/unpack 1.180000 0.000000 1.180000 ( 1.177197) > split/inject/<<+ 1.310000 0.000000 1.310000 ( 1.308850) > split/inject/+* 1.430000 0.010000 1.440000 ( 1.436653) > split/inject/+*= 1.640000 0.000000 1.640000 ( 1.637948) > split/zip/inject/+* 2.290000 0.000000 2.290000 ( 2.288469) > ohdeargodno 2.670000 0.000000 2.670000 ( 2.678789) > ipaddr/to_i 3.940000 0.010000 3.950000 ( 3.950504) Awesome! Glad to see I was able to provide the slowest solution ;) Ben