File: compilation_benchmark.py

package info (click to toggle)
simdutf 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,524 kB
  • sloc: cpp: 64,498; ansic: 15,347; python: 3,592; sh: 366; makefile: 12
file content (55 lines) | stat: -rwxr-xr-x 1,618 bytes parent folder | download
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
#!/usr/bin/env python3
#
# runs a compilation benchmark

import subprocess
import tempfile
import argparse
import datetime
import statistics


class Sample:
    def __init__(self, t0, t1, t2):
        self._configure = (t1-t0).total_seconds()
        self._compile = (t2-t1).total_seconds()

# benchmarks compilation, returns the time consumption


def measure_once(standard: int):
    builddir = tempfile.TemporaryDirectory()
    t0 = datetime.datetime.now()
    subprocess.run(["cmake", f"-DSIMDUTF_CXX_STANDARD={standard}", "-DSIMDUTF_FAST_TESTS=On",
                   "-B", builddir.name, "-GNinja"], stdout=subprocess.DEVNULL)
    t1 = datetime.datetime.now()
    subprocess.run(["cmake", "--build", builddir.name],
                   stdout=subprocess.DEVNULL)
    t2 = datetime.datetime.now()
    # print(f"configure took {t1-t0}, build took {t2-t1}")
    return Sample(t0, t1, t2)


def benchmark_single(standard: int, repetitions: int = 3):
    d = [measure_once(standard) for i in range(repetitions)]

    m = statistics.median([e._configure for e in d])
    print(f"median configure is {m:.3f}s")

    m = statistics.median([e._compile for e in d])
    print(f"median compile is {m:.3f}s")


def main():
    parser = argparse.ArgumentParser(
        prog='compilation benchmark',
        description='benchmarks compilation of simdutf')
    parser.add_argument('--standard', type=int, default=23)
    parser.add_argument('--repetitions', type=int, default=3)

    args = parser.parse_args()
    benchmark_single(standard=args.standard, repetitions=args.repetitions)


if __name__ == '__main__':
    main()