-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
54 lines (34 loc) · 1.07 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import io
import sys
import time
import PIL.Image
import png_header_injector
ITERATIONS = 32
def main(input_path):
use_pil(input_path)
use_header_injector(input_path)
def use_header_injector(input_path):
start = time.time()
for i in range(ITERATIONS):
inject_comment(input_path)
end = time.time()
print(
"Header injector total time: %0.3f seconds." % (end - start))
def inject_comment(input_path):
with open(input_path, "rb") as png:
out = io.BytesIO()
png_header_injector.replace_text(
png, out, {"Comment": "Test comment data."})
def use_pil(input_path):
start = time.time()
for i in range(ITERATIONS):
with PIL.Image.open(input_path) as png:
png_info = PIL.PngImagePlugin.PngInfo()
png_info.add_text("Comment", "Test comment data.")
out = io.BytesIO()
png.save(out, format="PNG", pnginfo=png_info)
end = time.time()
print(
"Pillow total time: %0.3f seconds." % (end - start))
if __name__ == "__main__":
main(sys.argv[1])