Encode `image` to PNG on `thread_count` threads in parallel. Returns: A `float` representing number of seconds that it takes all threads to finish encoding `image`.
(image, thread_count)
| 59 | |
| 60 | |
| 61 | def bench(image, thread_count): |
| 62 | """Encode `image` to PNG on `thread_count` threads in parallel. |
| 63 | |
| 64 | Returns: |
| 65 | A `float` representing number of seconds that it takes all threads |
| 66 | to finish encoding `image`. |
| 67 | """ |
| 68 | threads = [ |
| 69 | threading.Thread(target=lambda: encoder.encode_png(image)) |
| 70 | for _ in range(thread_count) |
| 71 | ] |
| 72 | start_time = datetime.datetime.now() |
| 73 | for thread in threads: |
| 74 | thread.start() |
| 75 | for thread in threads: |
| 76 | thread.join() |
| 77 | end_time = datetime.datetime.now() |
| 78 | delta = (end_time - start_time).total_seconds() |
| 79 | return delta |
| 80 | |
| 81 | |
| 82 | def _image_of_size(image_size): |