Title: RE: Test if string is a number?
Chris Wagner wrote, on Thu 6/30/2005 14:41

: At 12:16 PM 6/30/05 -0500, Joe Discenza wrote:
: >I bet you're right that "eval($var) eq $var + 0" works; have you
: >benchmarked it against all the other (regex, e.g.) methods presented?
:
: I haven't benchmarked it but I can garuntee that it's faster than a regex.
: Anything's faster than that. ;)  This should cover everything:

Thanks for playing. I compared your function with a regex I whipped up (/^[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?$/, which gave the same results, except for distinguishing "pure" numbers, on your dataset):

Benchmark: timing 100000 iterations of chris, regex...
     chris: 12 wallclock secs (11.86 usr +  0.00 sys = 11.86 CPU) @ 8432.41/s (n=100000)
     regex:  2 wallclock secs ( 1.56 usr +  0.00 sys =  1.56 CPU) @ 63979.53/s (n=100000)

Regex is pretty fast. Eval is usually pretty slow.

Joe


==============================================================
          Joseph P. Discenza, Sr. Programmer/Analyst
               mailto:[EMAIL PROTECTED]
 
          Carleton Inc.   http://www.carletoninc.com
          574.243.6040 ext. 300    fax: 574.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years
 
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to