Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/bench/src/cython/bench.py
1067 views
1
# mypy
2
from typing import Callable
3
4
5
def time(f: Callable, *args) -> int:
6
from time import time as time0
7
t = time0()
8
f(*args)
9
return int((time0() - t) * 1000)
10
11
12
benchmarks = []
13
14
15
def register(name: str, f: Callable) -> None:
16
global benchmarks
17
benchmarks.append((name, f))
18
19
20
def reset() -> None:
21
benchmarks.clear()
22
23
24
def all(desc: str = '') -> None:
25
print("-" * 20)
26
print("(Cython) Running...", desc)
27
t = 0
28
for (name, f) in benchmarks:
29
s = time(f)
30
t += s
31
print(name, s, "ms")
32
print("Total: ", t, "ms")
33
34