Skip to content

Commit cb66cfc

Browse files
rwlock: Add visualization code to benchmark
Not strictly necessary to check in but anyone who wants to run the benchmark will appreciate it.
1 parent a927485 commit cb66cfc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

benchmarks/rwlock_cache.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,26 @@ def write_time_series(
223223
ts_df.to_csv(csv_file, mode='a', header=False, index=False)
224224

225225

226+
def plot_series(path: str):
227+
"""Import and run this inside a notebook to visualize time series."""
228+
import matplotlib.pyplot as plt
229+
230+
df = pd.read_csv(path)
231+
df['timestamp'] = pd.to_datetime(df['timestamp'], format='ISO8601')
232+
233+
for (workers, ttl), group in df.groupby(['num_workers', 'ttl'], sort=True):
234+
group = group.sort_values('timestamp')
235+
fig, ax = plt.subplots(figsize=(10, 4))
236+
ax.plot(group['timestamp'], group['num_readers'], label='num_readers')
237+
ax.plot(group['timestamp'], group['num_waiting_writers'], label='num_waiting_writers')
238+
ax.set_title(f'num_workers={workers}, ttl={ttl}')
239+
ax.set_xlabel('Time')
240+
ax.set_ylabel('Count')
241+
ax.legend()
242+
ax.grid(alpha=0.3)
243+
plt.show()
244+
245+
226246
def display_metrics(
227247
n: int,
228248
ttl: Number,

dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build
22
click==8.0.4
33
invoke==2.2.0
4+
matplotlib
45
mock
56
packaging>=20.4
67
pandas

0 commit comments

Comments
 (0)