Skip to content

Commit

Permalink
Benchmark baseline on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 14, 2024
1 parent 2a73fe1 commit 2c2ed1a
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 23 deletions.
37 changes: 14 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
fail-fast: false
matrix:
python-version: [
"pypy3.10",
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
# "pypy3.10",
# "3.8",
# "3.9",
# "3.10",
# "3.11",
# "3.12",
"3.13",
"3.14",
"3",
"3.x",
# "3.14",
# "3",
# "3.x",
]
os: [
windows-latest,
macOS-latest,
# windows-latest,
# macOS-latest,
ubuntu-latest,
]

Expand All @@ -44,19 +44,10 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install -U pip
python3 -m pip install -U pytest
python3 -m pip install -U tqdm
python3 -m pip install -vvv coverage>=7.4.2
python3 -m pip install pillow-11.1.0.dev0-cp313-cp313-manylinux_2_28_x86_64-baseline.whl
- name: Test
run: |
python --version
python test.py
python -m pip --version
jq --version
- run: |
python -m pip install uv
uv --version
uv venv
uv pip install norwegianblue --color=always
python zlib-benchmark.py hopper.png
python zlib-benchmark.py effect_spread.png
Binary file added effect_spread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hopper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
125 changes: 125 additions & 0 deletions zlib-benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import io
import os
import sys
import timeit

from PIL import Image

# PATH = "Tests/images/hopper.png"
# PATH = "Tests/images/effect_spread.png"
PATH = sys.argv[1]
REPEAT = 1000

print(f"{Image.__version__ = }")
print(f"{Image.core.zlib_version = }")
print(f"Testing {PATH = } with {REPEAT} repetitions")


with open(PATH, "rb") as f:
data_in = f.read()

reader = io.BytesIO(data_in)
writer = io.BytesIO()

img = Image.open(reader)
img.load()


def read_png():
reader.seek(0, os.SEEK_SET)
return Image.open(reader)


def write_png(compress_level):
writer.seek(0, os.SEEK_SET)
writer.truncate(0)
img.save(writer, "PNG", compress_level=compress_level)


t = timeit.timeit(read_png, number=REPEAT * 10)
print(f"read PNG: time = {t:f} (sec)")


results = dict()
for compress_level in range(0, 10):
t = timeit.timeit(lambda: write_png(compress_level), number=REPEAT)
print(
f"write PNG: time = {t:f} (sec); "
f"size = {len(writer.getvalue())} bytes; "
f"{compress_level = }"
)
results[compress_level] = (len(writer.getvalue()), t)

header = f"{Image.core.zlib_version}/{os.path.basename(PATH)}"

print()
print(header)
for size, t in results.values():
print(t)

print()
print(header)
for size, t in results.values():
print(size)

# Image.open(io.BytesIO(writer.getvalue())).show()

# Image.__version__ = '11.1.0.dev0'
# Image.core.zlib_version = '1.3.1'
# Testing PATH = 'Tests/images/hopper.png' with 1000 repetitions
# read PNG: time = 0.121070 (sec)
# write PNG: time = 0.277860 (sec); size = 49353 bytes; compress_level = 0
# write PNG: time = 1.378973 (sec); size = 32403 bytes; compress_level = 1
# write PNG: time = 1.463843 (sec); size = 32156 bytes; compress_level = 2
# write PNG: time = 1.946944 (sec); size = 31792 bytes; compress_level = 3
# write PNG: time = 2.628619 (sec); size = 30715 bytes; compress_level = 4
# write PNG: time = 2.989835 (sec); size = 30529 bytes; compress_level = 5
# write PNG: time = 3.582502 (sec); size = 30343 bytes; compress_level = 6
# write PNG: time = 4.346017 (sec); size = 30277 bytes; compress_level = 7
# write PNG: time = 6.963706 (sec); size = 30183 bytes; compress_level = 8
# write PNG: time = 11.201260 (sec); size = 30166 bytes; compress_level = 9

# Image.__version__ = '11.1.0.dev0'
# Image.core.zlib_version = '1.3.1.zlib-ng'
# Testing PATH = 'Tests/images/hopper.png' with 1000 repetitions
# read PNG: time = 0.121355 (sec)
# write PNG: time = 0.243460 (sec); size = 49353 bytes; compress_level = 0
# write PNG: time = 0.484412 (sec); size = 40354 bytes; compress_level = 1
# write PNG: time = 0.582722 (sec); size = 31458 bytes; compress_level = 2
# write PNG: time = 0.647406 (sec); size = 31096 bytes; compress_level = 3
# write PNG: time = 0.849081 (sec); size = 30836 bytes; compress_level = 4
# write PNG: time = 0.699703 (sec); size = 30771 bytes; compress_level = 5
# write PNG: time = 0.916293 (sec); size = 30649 bytes; compress_level = 6
# write PNG: time = 1.426837 (sec); size = 30217 bytes; compress_level = 7
# write PNG: time = 1.855467 (sec); size = 30175 bytes; compress_level = 8
# write PNG: time = 2.772019 (sec); size = 30166 bytes; compress_level = 9

# Image.__version__ = '11.1.0.dev0'
# Image.core.zlib_version = '1.3.1'
# Testing PATH = 'Tests/images/effect_spread.png' with 1000 repetitions
# read PNG: time = 0.064432 (sec)
# write PNG: time = 0.271332 (sec); size = 49353 bytes; compress_level = 0
# write PNG: time = 1.590392 (sec); size = 42199 bytes; compress_level = 1
# write PNG: time = 1.749554 (sec); size = 42096 bytes; compress_level = 2
# write PNG: time = 2.188817 (sec); size = 41977 bytes; compress_level = 3
# write PNG: time = 2.496155 (sec); size = 41011 bytes; compress_level = 4
# write PNG: time = 2.278722 (sec); size = 40969 bytes; compress_level = 5
# write PNG: time = 2.514241 (sec); size = 40903 bytes; compress_level = 6
# write PNG: time = 2.503093 (sec); size = 40896 bytes; compress_level = 7
# write PNG: time = 2.616062 (sec); size = 40889 bytes; compress_level = 8
# write PNG: time = 2.614784 (sec); size = 40889 bytes; compress_level = 9

# Image.__version__ = '11.1.0.dev0'
# Image.core.zlib_version = '1.3.1.zlib-ng'
# Testing PATH = 'Tests/images/effect_spread.png' with 1000 repetitions
# read PNG: time = 0.062720 (sec)
# write PNG: time = 0.180120 (sec); size = 49353 bytes; compress_level = 0
# write PNG: time = 0.400339 (sec); size = 48241 bytes; compress_level = 1
# write PNG: time = 0.682549 (sec); size = 41287 bytes; compress_level = 2
# write PNG: time = 0.724561 (sec); size = 41168 bytes; compress_level = 3
# write PNG: time = 0.743060 (sec); size = 41134 bytes; compress_level = 4
# write PNG: time = 0.756581 (sec); size = 41120 bytes; compress_level = 5
# write PNG: time = 0.818945 (sec); size = 41118 bytes; compress_level = 6
# write PNG: time = 0.872731 (sec); size = 40895 bytes; compress_level = 7
# write PNG: time = 0.824981 (sec); size = 40889 bytes; compress_level = 8
# write PNG: time = 1.366639 (sec); size = 40889 bytes; compress_level = 9

0 comments on commit 2c2ed1a

Please sign in to comment.