forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_general.py
More file actions
69 lines (47 loc) · 1.3 KB
/
bench_general.py
File metadata and controls
69 lines (47 loc) · 1.3 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
2018-03-19.
Original means MSS 3.1.2.
Patched means MSS 3.2.0.
GNU/Linux Original Patched Gain %
grab 2618 2738 +4.58
access_rgb 1083 1128 +4.15
output 324 322 ------
save 320 319 ------
macOS
grab 524 526 ------
access_rgb 396 406 +2.52
output 194 195 ------
save 193 194 ------
Windows
grab 1280 2498 +95.16
access_rgb 574 712 +24.04
output 139 188 +35.25
"""
from time import time
import mss
import mss.tools
def grab(sct):
monitor = {"top": 144, "left": 80, "width": 1397, "height": 782}
return sct.grab(monitor)
def access_rgb(sct):
im = grab(sct)
return im.rgb
def output(sct, filename=None):
rgb = access_rgb(sct)
mss.tools.to_png(rgb, (1397, 782), output=filename)
def save(sct):
output(sct, filename="screenshot.png")
def benchmark(func):
count = 0
start = time()
with mss.mss() as sct:
while (time() - start) % 60 < 10:
count += 1
func(sct)
print(func.__name__, count)
benchmark(grab)
benchmark(access_rgb)
benchmark(output)
benchmark(save)