forked from markfinger/python-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf.py
More file actions
48 lines (39 loc) · 1.37 KB
/
Copy pathperf.py
File metadata and controls
48 lines (39 loc) · 1.37 KB
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
import time
from react.render import render_component
from .settings import Components
from .utils import clean_bundle_root
def median(l):
half = int(len(l) / 2)
l.sort()
if len(l) % 2 == 0:
return (l[half-1] + l[half]) / 2.0
else:
return l[half]
def run_perf_test():
render_component_times = []
rendered_components = []
iteration_count = 25
for i in range(iteration_count):
start = time.time()
rendered_components.append(
render_component(
Components.PERF_TEST,
props={'name': 'world'},
translate=True,
to_static_markup=True
)
)
end = time.time()
render_component_times.append(end - start)
clean_bundle_root()
for component in rendered_components:
assert str(component) == '<span>Hello world</span>'
print('Total time taken to render a component {iteration_count} times: {value}'.format(
iteration_count=iteration_count,
value=sum(render_component_times)
))
print('Times: {}'.format(render_component_times))
print('Max: {}'.format(max(render_component_times)))
print('Min: {}'.format(min(render_component_times)))
print('Mean: {}'.format(sum(render_component_times) / len(render_component_times)))
print('Median: {}'.format(median(render_component_times)))