File: benchmark.py

package info (click to toggle)
foot 1.25.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: ansic: 41,260; python: 474; sh: 181; xml: 57; makefile: 18
file content (51 lines) | stat: -rwxr-xr-x 1,302 bytes parent folder | download | duplicates (4)
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
#!/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())