Skip to content

Commit 6660907

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup
1 parent 0a65ebc commit 6660907

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

examples/performance_checker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Performance checker Example
22

3-
This example demonstrates using nipanel with Streamlit to display a dynamic sine wave using the `streamlit-echarts` library.
3+
This example measures the performance of a stremlit panel with a graph.
44

55
## Features
66

77
- Generates sine wave data with varying frequency
8-
- Displays the data in an chart
8+
- Displays the data in a graph
99
- Updates rapidly
1010
- Shows timing information
1111

examples/performance_checker/performance_checker_panel.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""A Streamlit visualization panel for the perf_check.py example script."""
1+
"""A Streamlit visualization panel for the performance_checker.py example script."""
22

33
import statistics
44
import time
@@ -51,6 +51,16 @@ def measure_get_value_time(
5151
if len(st.session_state.refresh_history) > 10:
5252
st.session_state.refresh_history.pop(0)
5353

54+
if st.session_state.refresh_history:
55+
refresh_history = st.session_state.refresh_history
56+
else:
57+
refresh_history = []
58+
59+
# Calculate statistics for refresh
60+
min_refresh_time = min(refresh_history) if refresh_history else 0
61+
max_refresh_time = max(refresh_history) if refresh_history else 0
62+
avg_refresh_time = statistics.mean(refresh_history) if refresh_history else 0
63+
5464
panel = nipanel.get_panel_accessor()
5565

5666
# Measure time to get each value
@@ -60,16 +70,6 @@ def measure_get_value_time(
6070
frequency, frequency_ms = measure_get_value_time(panel, "frequency", 1.0)
6171
unset_value, unset_value_ms = measure_get_value_time(panel, "unset_value", "default")
6272

63-
if st.session_state.refresh_history:
64-
history = st.session_state.refresh_history
65-
else:
66-
history = []
67-
68-
# Calculate statistics
69-
min_time = min(history) if history else 0
70-
max_time = max(history) if history else 0
71-
avg_time = statistics.mean(history) if history else 0
72-
7373
# Prepare data for echarts
7474
data = [{"value": [x, y]} for x, y in zip(time_points, sine_values)]
7575

@@ -108,9 +108,9 @@ def measure_get_value_time(
108108
st.metric("Frequency", f"{frequency:.2f} Hz")
109109
with col2:
110110
st.metric("Refresh Time", f"{time_since_last_refresh:.1f} ms")
111-
st.metric("Min Refresh Time", f"{min_time:.1f} ms")
112-
st.metric("Max Refresh Time", f"{max_time:.1f} ms")
113-
st.metric("Avg Refresh Time", f"{avg_time:.1f} ms")
111+
st.metric("Min Refresh Time", f"{min_refresh_time:.1f} ms")
112+
st.metric("Max Refresh Time", f"{max_refresh_time:.1f} ms")
113+
st.metric("Avg Refresh Time", f"{avg_refresh_time:.1f} ms")
114114

115115
with col3:
116116
st.metric("get time_points", f"{time_points_ms:.1f} ms")

0 commit comments

Comments
 (0)