The Running Time of +=

Skip Montanaro skip at pobox.com
Tue Mar 22 20:16:46 CET 2005


>>>>> "Haz" == MyHaz  <support.services.complaints at gmail.com> writes:

    Haz> Teach me how to fish, where would i find out more about the
    Haz> internal representations of data types in python

The source.

Experimentally you can use the timeit command to see how it performs:

% for i in 10 20 40 80 160 320 640 1280 ; do
> timeit.py -s 'a = "a"*'$i' ; b = "b"*10' 'a += b'
> done
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.826 usec per loop

% for i in 10 20 40 80 160 320 640 1280 ; do
> timeit.py -s 'a = "a"*10 ; b = "b"*'$i 'a += b'
> done
1000000 loops, best of 3: 0.826 usec per loop
1000000 loops, best of 3: 0.909 usec per loop
1000000 loops, best of 3: 1.11 usec per loop
1000000 loops, best of 3: 1.52 usec per loop
100000 loops, best of 3: 1.97 usec per loop
100000 loops, best of 3: 3.18 usec per loop
100000 loops, best of 3: 5.54 usec per loop
100000 loops, best of 3: 10.5 usec per loop

Skip



More information about the Python-list mailing list