Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/bench/measure_time.py
2723 views
1
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
import os, sys, time, numpy
3
4
try:
5
import scipy
6
from scipy import mean, stats
7
except ModuleNotFoundError:
8
print("Warning: scipy package is not installed, confidence values will not be available")
9
stats = None
10
11
duration_list = []
12
13
DEFAULT_CYCLES_TO_RUN = 100
14
cycles_to_run = DEFAULT_CYCLES_TO_RUN
15
16
try:
17
cycles_to_run = sys.argv[3] if sys.argv[3] else DEFAULT_CYCLES_TO_RUN
18
cycles_to_run = int(cycles_to_run)
19
except IndexError:
20
pass
21
except (ValueError, TypeError):
22
cycles_to_run = DEFAULT_CYCLES_TO_RUN
23
print("Error: Cycles to run argument must be an integer. Using default value of {}".format(DEFAULT_CYCLES_TO_RUN))
24
25
# Numpy complains if we provide a cycle count of less than 3 ~ default to 3 whenever a lower value is provided
26
cycles_to_run = cycles_to_run if cycles_to_run > 2 else 3
27
28
for i in range(1,cycles_to_run):
29
start = time.perf_counter()
30
31
# Run the code you want to measure here
32
os.system(sys.argv[1])
33
34
end = time.perf_counter()
35
36
duration_ms = (end - start) * 1000
37
duration_list.append(duration_ms)
38
39
# Stats
40
mean = numpy.mean(duration_list)
41
std_err = stats.sem(duration_list)
42
43
print("SUCCESS: {} : {:.2f}ms +/- {:.2f}% on luau ".format('duration', mean,std_err))
44
45