Speed of str(positive_integer)..
From: alejandro david weil (aweil_at_mail.ru)
Date: 06/29/04
- Next message: Michel Claveau/Hamster: "Re: Drawing with python."
- Previous message: Christopher T King: "Re: How important is Python 1.5 compatibility?"
- Next in thread: Christopher T King: "Re: Speed of str(positive_integer).."
- Reply: Christopher T King: "Re: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: alejandro david weil: "Re: Speed of str(positive_integer).."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Jun 2004 19:58:38 -0300 To: python-list@python.org
I asked myself how much slower would be an integer-positive number to
string convertion function against the default str().
And this function:
def myconv(number):
if number==0:
return '0'
s = ''
l = dig
while number > 0:
n = number//10
t = number-((n*10))
s = l[t]+s
number = n
return s
throw these results (using Psyco):
Testing 10000 times with numbers upto: 100
------------------------------------------
str(object) -> string -> 1.39086294174
Simplest for integer>0 (myconv) -> 0.463662147522
This should be faster but don't -> 1.7972369194
Testing numbers upto 1000000
----------------------------
str(object) -> string -> 1.48166298866
Simplest for integer>0 (myconv) -> 1.89623999596
This should be faster but don't -> 6.55253386497
Notes:
* It was faster for little numbers, and it seems that with
numbers growing gets worse.
*Without psyco, my native myconv is slower than str().
*Obviously, a simple list with the first 256 mixed with
str() (as I propoused on the previous thread :-) breaks all
the stats! (With and without psyco..)
*The thrid test is using divmod() that i thought that would be
faster (i thought it could make only one division and get both
qoutient and remainder, without having to multiply..) but
was worse.
*Also tried that function using lists instead of strings,
but gaves worse results.
I include the source (with all the functions), so you can play with it. :-)
See ya,
alejandro
PS: I want a faster divmod! :-)
-- + There is no dark side of the moon really. Matter of fact it's all dark.
- text/x-python attachment: test_strconv.py
- Next message: Michel Claveau/Hamster: "Re: Drawing with python."
- Previous message: Christopher T King: "Re: How important is Python 1.5 compatibility?"
- Next in thread: Christopher T King: "Re: Speed of str(positive_integer).."
- Reply: Christopher T King: "Re: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: Tony Meyer: "RE: Speed of str(positive_integer).."
- Maybe reply: alejandro david weil: "Re: Speed of str(positive_integer).."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|