mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
scripts: benchmarking utility script
This commit is contained in:
parent
d9028b2394
commit
a4b1c09d58
1 changed files with 51 additions and 0 deletions
51
scripts/benchmark.py
Executable file
51
scripts/benchmark.py
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env -S python3 -u
|
||||
|
||||
import argparse
|
||||
import fcntl
|
||||
import os
|
||||
import statistics
|
||||
import struct
|
||||
import sys
|
||||
import termios
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('files', type=argparse.FileType('rb'), nargs='+')
|
||||
parser.add_argument('--iterations', type=int, default=20)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
lines, cols, height, width = struct.unpack(
|
||||
'HHHH',
|
||||
fcntl.ioctl(sys.stdout.fileno(),
|
||||
termios.TIOCGWINSZ,
|
||||
struct.pack('HHHH', 0, 0, 0, 0)))
|
||||
|
||||
times = {name: [] for name in [f.name for f in args.files]}
|
||||
|
||||
for f in args.files:
|
||||
bench_bytes = f.read()
|
||||
|
||||
for i in range(args.iterations):
|
||||
start = datetime.now()
|
||||
sys.stdout.buffer.write(bench_bytes)
|
||||
stop = datetime.now()
|
||||
|
||||
times[f.name].append((stop - start).total_seconds())
|
||||
|
||||
del bench_bytes
|
||||
|
||||
print('\033[J')
|
||||
print(times)
|
||||
print(f'cols={cols}, lines={lines}, width={width}px, height={height}px')
|
||||
for f in args.files:
|
||||
print(f'{os.path.basename(f.name)}: '
|
||||
f'{statistics.mean(times[f.name]):.3f}s '
|
||||
f'±{statistics.stdev(times[f.name]):.3f}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue