aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/benchmark.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/benchmark.py b/scripts/benchmark.py
new file mode 100755
index 00000000..5483dac1
--- /dev/null
+++ b/scripts/benchmark.py
@@ -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())