Skip to content

Commit 9f0aef0

Browse files
committed
tests: update bench_bgra2rgb.py
1 parent 962ff34 commit 9f0aef0

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

tests/bench_bgra2rgb.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,29 @@
66
77
88
GNU/Linux
9-
pil_frombytes 595
10-
mss_rgb 437
11-
numpy_flip 183
12-
numpy_slice 156
9+
pil_frombytes_rgb 51
10+
pil_frombytes 139
11+
mss_rgb 119
12+
numpy_flip 31
13+
numpy_slice 29
1314
1415
macOS
15-
pil_frombytes 115
16-
mss_rgb 108
17-
numpy_flip 67
18-
numpy_slice 65
16+
pil_frombytes_rgb 113
17+
pil_frombytes 209
18+
mss_rgb 174
19+
numpy_flip 39
20+
numpy_slice 36
1921
2022
Windows
21-
pil_frombytes 294
22-
mss_rgb 261
23-
numpy_flip 124
24-
numpy_slice 115
23+
pil_frombytes_rgb 42
24+
pil_frombytes 81
25+
mss_rgb 66
26+
numpy_flip 25
27+
numpy_slice 22
2528
"""
2629

30+
from __future__ import print_function
31+
2732
import time
2833

2934
import numpy
@@ -45,24 +50,29 @@ def numpy_slice(im):
4550
return numpy.array(im, dtype=numpy.uint8)[..., [2, 1, 0]].tobytes()
4651

4752

53+
def pil_frombytes_rgb(im):
54+
return Image.frombytes('RGB', im.size, im.rgb).tobytes()
55+
56+
4857
def pil_frombytes(im):
4958
return Image.frombytes('RGB', im.size, im.bgra, 'raw', 'BGRX').tobytes()
5059

5160

52-
def benchmark(func):
61+
def benchmark():
5362
with mss.mss() as sct:
54-
m = {'top': 0, 'left': 0, 'width': 640, 'height': 480}
55-
count = 0
56-
start = time.time()
57-
58-
while (time.time() - start) <= 1:
59-
frame = func(sct.grab(m)) # noqa
60-
count += 1
61-
62-
print(func.__name__, count)
63-
64-
65-
benchmark(pil_frombytes)
66-
benchmark(mss_rgb)
67-
benchmark(numpy_flip)
68-
benchmark(numpy_slice)
63+
im = sct.grab(sct.monitors[0])
64+
for func in (pil_frombytes_rgb,
65+
pil_frombytes,
66+
mss_rgb,
67+
numpy_flip,
68+
numpy_slice):
69+
count = 0
70+
start = time.time()
71+
while (time.time() - start) <= 1:
72+
func(im)
73+
im._ScreenShot__rgb = None
74+
count += 1
75+
print(func.__name__.ljust(17), count)
76+
77+
78+
benchmark()

0 commit comments

Comments
 (0)