[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] converting byte image for display



I did also some benchmarking with interesting results.

test_list = "a"*10**6
test_count = 10

con_cat = 29.4 , 1x
map1 = 12.6 , 2.3x
map2 = 12.5, 2.4x
list_com = 4.6, 6,4x

let's add
import psyco
psyco.full()

con_cat = 4.4 , 1x
map1 = 15.6 , 0.28x and 0.8x compared to situation without psyco
map2 = 15.8, 0.28x
list_com = 2.8, 1.6x

psyco + list_com = 10.5x improvement.

Thank you for the help!
--HannuK




On 1/2/06, Guillaume Proux <gproux@xxxxxxxxx> wrote:
> Very nice...
>
> It seems some old tricks do not apply anymore.
> In any case, getting rid of function calls in inner loops are always a
> good idea even with the newest list comprehension optimizations.
>
> Regards,
>
> Guillaume
>
> Guillaume
>
> On 1/2/06, Trevor Fancher <trevor@xxxxxxxxxxx> wrote:
> >
> > On Jan 1, 2006, at 9:00 PM, Simon Wittber wrote:
> > > Benchmarks are fun.
> >
> > Sure are.  :)
> >
> >
> > > In your test_concat function, you are testing a function call as well
> > > as the concat process. This will add extra time to that benchmark,
> > > which the other benchmarks don't have.
> >
> > I noticed this but left the function call in on purpose because that
> > is what the original poster was going to be doing anyways.
> >
> >
> > > Also, you are using a very small 3 item list for the test. a 320x200
> > > 256 color image will have 64000 bytes.
> > >
> > > Using
> > >
> > > test_list = "a" * 64000
> > > test_count = 100
> > >
> > > these were my results:
> > >
> > > concat: 6.103
> > >   map1: 6.349
> > >   map2: 6.303
> > >
> > > String concantenation used to be quite slow in Python 2.3, but has
> > > since recieved some optimisation.
> > >
> > > http://mail.python.org/pipermail/python-list/2004-September/
> > > 242125.html
> >
> > http://mail.python.org doesn't want to load for me but
> > http://python.org will, weird.
> >
> > Anyways, it appears that string concatenation is now faster than using
> > the built-in function join and map.
> >
> >
> > > Also, you may want to try using a list comprehension, which will be
> > > quite fast.
> > >
> > > def test_list_comp(test_count, test_list):
> > >    t = pygame.time.get_ticks()
> > >    for i in range(test_count):
> > >       a = ''.join([i*3 for i in test_list])
> > >    return pygame.time.get_ticks() - t
> > >
> > >
> > > This score 2.743 on my box.
> >
> > Yep, list comprehension was significantly faster on my box too.  Thanks
> > for the suggestion.
> >
> >
> > > -Sw.
> > __
> > Trevor Fancher
> > http://fancher.org
> >
> >
> >
> >
>