On Jun 10, 7:01 am, Alexey Nezhdanov <[email protected]> wrote:
> I get these results (best timing):
>   try-variant: 10.24s
>   regex: 9.58s
> So on my laptop try:except: function loses about 5% to regex - probably it
> depends on hardware/OS.

Interesting, which python/platform are you using ?

> And as Massimo pointed out - we don't really check for an int - we check for
> valid id. Function should be remamed, yes.

Right, it's more like is_convertible_to_int. Now that we are more
clear about what we're looking for, it sounds exactly like
string.isdigit() to me.

b...@black:/tmp$ python -m timeit "s=[str(i) for i in range(10000)]"
"import re" "integer_pat=re.compile('[+-]?[0-9]{1,15}$')"
"is_integer=integer_pat.match"
100 loops, best of 3: 3.64 msec per loop

b...@black:/tmp$ python -m timeit "s=[str(i) for i in range(10000)]"
"import re" "integer_pat=re.compile('[+-]?[0-9]{1,15}$')"
"is_integer=integer_pat.match" "for i in s:"  "  is_integer(i)"
100 loops, best of 3: 9.87 msec per loop

b...@black:/tmp$ python -m timeit "s=[str(i) for i in range(10000)]"
"for i in s:"  "  i.isdigit()"
100 loops, best of 3: 4.63 msec per loop

Which gives a 6.2x (!) faster result.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to