Re: How to increase the speed of this program?
- From: "Klaas" <mike.klaas@xxxxxxxxx>
- Date: 28 Nov 2006 11:11:56 -0800
John Machin wrote:
Thanks, that's indeed faster than array(t, [v]*n) but what I had in
mind was something like an additional constructor:
array.filledarray(typecode, repeat_value, repeat_count)
which I speculate should be even faster. Looks like I'd better get a
copy of arraymodule.c and start fiddling.
Anyone who could use this? Suggestions on name? Argument order?
Functionality: same as array.array(typecode, [repeat_value]) *
repeat_count. So it would cope with array.filledarray('c', "foo", 10)
Why not just optimize array.__mul__? The difference is clearly in the
repeated memcpy() in arraymodule.c:683. Pseudo-unrolling the loop in
python demonstrates a speed up:
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c',['\0'])*100000"
100 loops, best of 3: 3.14 msec per loop
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c',['\0','\0','\0','\0'])*25000"
1000 loops, best of 3: 732 usec per loop
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c','\0'*20)*5000"10000 loops, best of 3: 148 usec per loop
Which is quite close to your fromstring solution:
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c').fromstring('\0'*100000)"
10000 loops, best of 3: 137 usec per loop
In fact, you can make it about 4x faster by balancing:
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c','\0'*200)*500"
10000 loops, best of 3: 32.4 usec per loop
For the record:
[klaas@worbo ~]$ python -m timeit -s "from array import array"
"array('c','\0'*100000)"
10000 loops, best of 3: 140 usec per loop
-Mike
.
- Follow-Ups:
- Re: How to increase the speed of this program?
- From: Klaas
- Re: How to increase the speed of this program?
- References:
- How to increase the speed of this program?
- From: HYRY
- Re: How to increase the speed of this program?
- From: Leo Kislov
- Re: How to increase the speed of this program?
- From: Peter Otten
- Re: How to increase the speed of this program?
- From: Peter Otten
- Re: How to increase the speed of this program?
- From: John Machin
- Re: How to increase the speed of this program?
- From: Fredrik Lundh
- Re: How to increase the speed of this program?
- From: John Machin
- How to increase the speed of this program?
- Prev by Date: Re: How to increase the speed of this program?
- Next by Date: Wrapping A Shell
- Previous by thread: Re: How to increase the speed of this program?
- Next by thread: Re: How to increase the speed of this program?
- Index(es):
Relevant Pages
|