From: Daniel Sheppard Date: 2007-11-30T11:42:37+09:00 Subject: Re: FEATURE SUGGESTION: Accept default value for to_f and to_i > 6) would avoid expensive regular expressions First, you'd have to conjure up some expensive regular expressions, you'll find that regular expressions are much more efficient that you might think. Pointless micro-benchmark time. String input of 'ab', 1 million iterations. user system total real string.to_i 0.625000 0.000000 0.625000 ( 0.657000) Integer(string) rescue 57 32.422000 0.782000 33.204000 ( 34.844000) /^-?\d+$/===string ? string.to_i : 57 1.125000 0.000000 1.125000 ( 1.218000) string.to_f 0.718000 0.000000 0.718000 ( 0.843000) Float(string) rescue 57 32.281000 0.765000 33.046000 ( 34.750000) /^-?\d+(?=\.\d+)?$/===string ? string.to_f : 57 0.672000 0.000000 0.672000 ( 0.734000) The only advantage to your proposal is to optimise an exceptional case. If it's not an exceptional case, regex validation gives you almost as much speed as you'd get with raw C. Once you've written an application with this functionality, benchmarked it, and found that that validation of string data as numeric is your problem, you can go off and write a C extension to do what you want. Raising this discussion before that point is just wasting your time. Dan.