9 jupytext_version: 1.11.1
11 display_name: Python 3 (ipykernel)
16 ```python Collapsed="false"
22 import matplotlib.pyplot as plt
26 ```python Collapsed="false" tags=[]
27 ! cd .. && for i in {01..25}; do cabal run advent${i} --enable-profiling -- +RTS -N -pj -s -hT ; done
35 ```python Collapsed="false" tags=[]
36 ! cd .. && for i in {01..25}; do /usr/bin/time -f "%C,%S,%E,%M" -o times.csv -a cabal run advent${i}; done
39 ```python Collapsed="false" tags=[]
40 ! cd .. && for i in {01..25}; do /usr/bin/time -f "%C,%S,%E,%M" -o times_raw.csv -a advent${i}; done
52 !mv ../times_raw.csv .
60 ! for f in *hp ; do hp2ps ${f} ; done
63 ```python Collapsed="false"
64 len(glob.glob('*prof'))
67 ```python Collapsed="false"
69 for fn in glob.glob('*prof'):
73 for n in 'program total_time total_alloc total_ticks initial_capabilities'.split():
79 ```python Collapsed="false"
80 performance = pd.DataFrame(profs).set_index('program').sort_index()
84 ```python Collapsed="false"
85 performance.total_ticks.plot.bar()
88 ```python Collapsed="false"
89 performance.total_ticks.plot.bar(logy=True)
92 ```python Collapsed="false"
93 performance.total_alloc.plot.bar()
96 ```python Collapsed="false"
97 performance.total_alloc.plot.bar(logy=True)
100 ```python Collapsed="false"
101 performance[['total_ticks', 'total_alloc']].plot.bar(
102 logy=True, secondary_y=['total_alloc'],
103 figsize=(8, 6), title="Internal time and memory")
104 plt.savefig('internal_time_and_memory_log.png')
107 ```python Collapsed="false"
108 performance[['total_ticks', 'total_alloc']].plot.bar(
109 logy=False, secondary_y=['total_alloc'],
110 figsize=(8, 6), title="Internal time and memory")
111 plt.savefig('internal_time_and_memory_linear.png')
115 # times = pd.read_csv('times.csv',
116 # names=['program', 'system', 'elapsed', 'memory'],
117 # index_col='program')
118 # times.index = times.index.str.slice(start=len('cabal run '))
119 # times.elapsed = pd.to_numeric(times.elapsed.str.slice(start=2))
124 times = pd.read_csv('times_raw.csv',
125 names=['program', 'system', 'elapsed', 'memory'],
127 times.elapsed = pd.to_numeric(times.elapsed.str.slice(start=2))
135 ```python Collapsed="false"
139 ```python Collapsed="false"
140 performance = performance.merge(times, left_index=True, right_index=True)
141 # performance.drop(index='advent15loop', inplace=True)
145 ```python Collapsed="false"
149 ```python Collapsed="false"
150 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
151 performance[['elapsed', 'memory']].plot.bar(
152 logy=True, secondary_y=['memory'],
153 figsize=(8, 6), title="External time and memory")
154 plt.savefig('external_time_and_memory_log.png')
157 ```python Collapsed="false"
158 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
159 performance[['elapsed', 'memory']].plot.bar(
160 logy=False, secondary_y=['memory'],
161 figsize=(8, 6), title="External time and memory")
162 plt.savefig('external_time_and_memory_linear.png')
165 ```python Collapsed="false"
166 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
167 performance[['total_ticks', 'elapsed']].plot.bar(
168 logy=True, secondary_y=['elapsed'],
169 figsize=(8, 6), title="Internal vs external time")
170 plt.savefig('internal_external_time.png')
173 ```python Collapsed="false"
174 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
175 performance[['total_ticks', 'elapsed']].plot.bar(
176 logy=False, secondary_y=['elapsed'],
177 figsize=(8, 6), title="Internal vs external time")
178 plt.savefig('internal_external_time_linear.png')
181 ```python Collapsed="false"
182 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
183 performance[['total_alloc', 'memory']].plot.bar(
184 logy=True, secondary_y=['memory'],
185 figsize=(8, 6), title="Internal vs external memory")
186 plt.savefig('internal_external_memory_log.png')
189 ```python Collapsed="false"
190 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
191 performance[['total_alloc', 'memory']].plot.bar(
192 logy=False, secondary_y=['memory'],
193 figsize=(8, 6), title="Internal vs external memory")
194 plt.savefig('internal_external_memory_linear.png')
197 ```python Collapsed="false"
198 # performance['elapsed_adj'] = performance['elapsed'] - 0.28
202 ```python Collapsed="false"
203 # performance[['total_time', 'elapsed_adj']].plot.bar(logy=True)
206 ```python Collapsed="false"
207 fig, ax = plt.subplots(ncols=3, figsize=(20,5))
209 performance['elapsed'].plot.bar(ax=ax[2],
211 title="Run times (wall clock), log scale",
214 ax[2].set_xlabel('Program')
216 performance['elapsed'].plot.bar(ax=ax[0],
218 title="Run times (wall clock), linear scale",
221 ax[0].set_xlabel('Program')
223 performance['elapsed'].plot.bar(ax=ax[1],
226 title="Run times (wall clock), truncated linear scale",
229 ax[1].set_xlabel('Program')
231 plt.savefig('run_times_combined.png')
234 ```python Collapsed="false"
235 fig, ax = plt.subplots(ncols=2, figsize=(13,5))
237 performance['memory'].plot.bar(ax=ax[0],
239 title="Memory used, log scale",
242 ax[0].set_xlabel('Program')
244 performance['memory'].plot.bar(ax=ax[1],
246 title="Memory used, linear scale",
249 ax[1].set_xlabel('Program')
251 plt.savefig('memory_combined.png')
254 ```python Collapsed="false"
255 # ax = performance['elapsed_adj'].plot.bar(logy=False,
256 # title="Run times (wall clock), linear scale",
258 # ax.set_xlabel('Program')
259 # plt.savefig('run_times_linear.png')
262 ```python Collapsed="false"
266 ```python Collapsed="false"
267 performance['memory'].plot.bar()
270 ```python Collapsed="false"
271 performance.plot.scatter('elapsed', 'total_alloc', logx=True, logy=True)
274 ```python Collapsed="false"
275 performance.plot.scatter('memory', 'total_alloc', logx=True, logy=True)
278 ```python Collapsed="false"
279 performance.plot.scatter('elapsed', 'total_ticks', logx=True, logy=True)
282 ```python Collapsed="false"
283 performance[['total_alloc', 'memory', 'elapsed']].to_csv('performance.csv')
286 ```python Collapsed="false"
287 print(performance[['total_alloc', 'elapsed', 'memory']].to_markdown(floatfmt=['0.0f', '0.0f', '.2f', '0.0f']))