-
Notifications
You must be signed in to change notification settings - Fork 969
/
test_compile_benchmark.py
121 lines (85 loc) ยท 2.53 KB
/
test_compile_benchmark.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""Benchmark the time it takes to compile a reflex app."""
import importlib
import reflex
rx = reflex
class State(rx.State):
"""A simple state class with a count variable."""
count: int = 0
def increment(self):
"""Increment the count."""
self.count += 1
def decrement(self):
"""Decrement the count."""
self.count -= 1
class SliderVariation(State):
"""A simple state class with a count variable."""
value: int = 50
def set_end(self, value: int):
"""Increment the count.
Args:
value: The value of the slider.
"""
self.value = value
def sample_small_page() -> rx.Component:
"""A simple page with a button that increments the count.
Returns:
A reflex component.
"""
return rx.vstack(
*[rx.button(State.count, font_size="2em") for i in range(100)],
spacing="1em",
)
def sample_large_page() -> rx.Component:
"""A large page with a slider that increments the count.
Returns:
A reflex component.
"""
return rx.vstack(
*[
rx.vstack(
rx.heading(SliderVariation.value),
rx.slider(on_change_end=SliderVariation.set_end),
width="100%",
)
for i in range(100)
],
spacing="1em",
)
def add_small_pages(app: rx.App):
"""Add 10 small pages to the app.
Args:
app: The reflex app to add the pages to.
"""
for i in range(10):
app.add_page(sample_small_page, route=f"/{i}")
def add_large_pages(app: rx.App):
"""Add 10 large pages to the app.
Args:
app: The reflex app to add the pages to.
"""
for i in range(10):
app.add_page(sample_large_page, route=f"/{i}")
def test_mean_import_time(benchmark):
"""Test that the mean import time is less than 1 second.
Args:
benchmark: The benchmark fixture.
"""
def import_reflex():
importlib.reload(reflex)
# Benchmark the import
benchmark(import_reflex)
def test_mean_add_small_page_time(benchmark):
"""Test that the mean add page time is less than 1 second.
Args:
benchmark: The benchmark fixture.
"""
app = rx.App(state=State)
benchmark(add_small_pages, app)
def test_mean_add_large_page_time(benchmark):
"""Test that the mean add page time is less than 1 second.
Args:
benchmark: The benchmark fixture.
"""
app = rx.App(state=State)
results = benchmark(add_large_pages, app)
print(results)