-
Notifications
You must be signed in to change notification settings - Fork 102
/
benchmark.py
47 lines (33 loc) · 1.2 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
"""
benchmark
~~~~~~~~~
A simple script for running benchmarks on captured process output.
Example run::
$ BENCHMARK=tests/captured/ls.input python benchmark.py
.....................
ls.input: Mean +- std dev: 644 ns +- 23 ns
:copyright: (c) 2016-2021 by pyte authors and contributors,
see AUTHORS for details.
:license: LGPL, see LICENSE for more details.
"""
import io
import os.path
import sys
from functools import partial
try:
from pyperf import Runner
except ImportError:
sys.exit("``perf`` not found. Try installing it via ``pip install perf``.")
import pyte
def make_benchmark(path, screen_cls):
with io.open(path, "rt", encoding="utf-8") as handle:
data = handle.read()
stream = pyte.Stream(screen_cls(80, 24))
return partial(stream.feed, data)
if __name__ == "__main__":
benchmark = os.environ["BENCHMARK"]
sys.argv.extend(["--inherit-environ", "BENCHMARK"])
runner = Runner()
for screen_cls in [pyte.Screen, pyte.DiffScreen, pyte.HistoryScreen]:
name = os.path.basename(benchmark) + "->" + screen_cls.__name__
runner.bench_func(name, make_benchmark(benchmark, screen_cls))