On 9/26/06, Yukihiro M. [email protected] wrote:
full year.
matz.
Thanks matz,
I tried out the code and it looks better in a few spots, but it also got
worse in a few (but not as common). You can still use enormous amounts
of
memory because of the copy-on-write mechanism. I am attaching a
testbench
for testing runtime and memory (sorry, linux only) performance for a
bunch
of array operations that can be O(1). It also includes some new tests
at
the end (didn’t have these before) that show O(n**2) memory when it
should
be O(n). All of those performance (memory and runtime) issues were
fixed in
my patch.
Here are the results (for just 2^12=4096 iterations/elements):
- : needs work, still not to O(1)
- : partially improved, still not to O(1)
– : worse
code 2006-09-01 2006-09-26 eric’s-patch
sec kB sec kB sec kB
---- ---- ---- ---- ---- ----
; 0.01 132 0.00 0 0.01 136
shift 0.01 148 0.00 132 0.00 144
shift(1) 0.01 152 0.13- 136 0.01 152
pop 0.01 128 0.01 132 0.01 144
pop(1) 0.01 152 0.00 136 0.01 152
shift;pop 0.01 132 0.01 136 0.01 156
shift(1);pop(1) 0.01 136 0.14- 140 0.01 164
unshift(i) 0.13 132 0.01+ 140 0.00 132
push(i) 0.01 132 0.01 0 0.01 132
unshift(i);push(i) 0.14 0 0.00+ 200 0.01 208
unshift(shift) 0.59 4816 0.00+ 0 0.01 140
unshift(shift(1)) 0.60 4816 0.13 68 0.01 148
push(pop) 0.01 132 0.00 0 0.01 140
push(*pop(1)) 0.38 4816 0.00+ 8 0.01 148
push(shift) 0.45 4816 0.00+ 0 0.01 140
push(shift(1)) 0.45 4816 0.14 8 0.01 148
unshift(pop) 0.14 132 0.00+ 60 0.01 140
unshift(pop(1)) 0.51 4816 0.01+ 68 0.01 148
slice!(1) 0.13 148 0.56-- 132 0.00 144
delete_at(1) 0.14 148 0.55-- 132 0.00 144
slice!(1,1) 0.58 8124 0.58- 8264 0.01 152
self[1,1]=[] 0.14 552 0.13- 536 0.01 548
slice!(-2) 0.00 148 0.00 132 0.00 144
delete_at(-2) 0.00 148 0.00 132 0.00 144
slice!(-2,1) 0.45 8120 0.46- 8260 0.01 148
self[-2,1]=[] 0.01 544 0.01 528 0.00 544
self[1,0]=[i] 0.16 140 0.14- 4 0.00 304
insert(1,i) 0.16 136 0.14- 0 0.00 304
self[-1,0]=[i] 0.02 136 0.01 4 0.01 308
insert(-2,i) 0.02 132 0.01 0 0.01 308
self[1,0]=slice!(1,1) 0.76 4056 0.77- 3956 0.01 144
insert(1,delete_at(1)) 0.27 136 0.81-- 4 0.01 144
self[-1,0]=slice!(-2,1) 0.56 4056 0.58 3956 0.02 144
insert(-2,delete_at(-2)) 0.01 136 0.01 4 0.01 144
self[-1,0]=slice!(1,1) 0.73 4052 0.69- 3952 0.01 276
insert(-2,delete_at(1)) 0.13 132 0.63-- 0 0.01 276
self[1,0]=slice!(-2,1) 0.72 4052 0.74- 3952 0.01 212
insert(1,delete_at(-2)) 0.17 132 0.17- 0 0.01 212
self[i]=self[i] 0.00 136 0.00 4 0.01 140
self[i]=at(i) 0.00 136 0.01 4 0.00 140
self[i,1]=self[i,1] 0.50 3960 0.50- 3952 0.01 144
self[-i-1]=self[-i-1] 0.01 140 0.01 8 0.02 144
self[-i-1]=at(-i-1) 0.02 140 0.01 8 0.01 144
self[-i-1,1]=self[-i-1,1] 0.49 4056 0.50- 3956 0.01 144
self[-i-1]=self[i] 0.01 132 0.01 0 0.01 136
self[-i-1]=at(i) 0.01 132 0.01 0 0.01 136
self[-i-1,1]=self[i,1] 0.57 4044 0.59- 3948 0.01 140
self[i]=self[-i-1] 0.01 136 0.01 4 0.01 140
self[i]=at(-i-1) 0.01 136 0.01 4 0.01 140
self[i,1]=self[-i-1,1] 0.56 4048 0.59- 3952 0.02 140
push(shift(1)) 8.15 393900 0.24 4 0.02 312
unshift(pop(1)) 4.80 393920 0.01+ 60 0.02 308
insert(-1,slice!(0,1)) 6.05 262964 36.24- 262836 0.04 404
insert(0,slice!(-1,1)) 2.71 262980 73.98- 262852 0.03 304
self[i]=self[i,1] 9.84 262924 18.77- 262832 0.02 268
self[-i-1]=self[-i-1,1] 8.36 262976 39.82- 262820 0.03 272
self[-i-1]=self[i,1] 5.94 262840 38.00- 262816 0.03 132
self[i]=self[-i-1,1] 0.90 262824 19.97- 262800 0.03 136
Notice how bad the memory and runtime is for these last ones. And this
is
only for 4096 elements/iterations!
I think the rest of array.c should be overhauled just like I had to do
in my
original patch.
I still would like to see the same done for String sometime. The same
issues exist. You’ll find many deficiencies even without shift/unshift
(but
with the equivalent functionality). I’d like the extra performance to
build
a fast character FIFO with a String.
Eric