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

Re: [pygame] converting byte image for display



On 1/2/06, Trevor Fancher <trevor@xxxxxxxxxxx> wrote:
> However, my benchmarking code may be extremely flawed because, as I
> said, I am new to python.  If you don't mind, could you correct my
> benchmarking code or explain why test_concat is running faster?


Benchmarks are fun.

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.

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

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.

-Sw.