9 jupytext_version: 1.11.1
11 display_name: Python 3 (ipykernel)
16 ```python Collapsed="false"
24 import matplotlib.pyplot as plt
29 ! cd .. && cabal install
32 ```python Collapsed="false" tags=[]
33 ! cd .. && for i in {01..25}; do cabal run advent${i} --enable-profiling -- +RTS -N -pj -s -hT ; done
41 ```python Collapsed="false" tags=[]
42 ! cd .. && for i in {01..25}; do /usr/bin/time -f "%C,%S,%E,%M" -o times.csv -a cabal run advent${i}; done
45 ```python Collapsed="false" tags=[]
46 ! cd .. && for i in {01..25}; do /usr/bin/time -f "%C,%S,%E,%M" -o times_raw.csv -a advent${i}; done
58 !mv ../times_raw.csv .
66 ! for f in *hp ; do hp2ps ${f} ; done
69 ```python Collapsed="false"
73 ```python Collapsed="false"
75 for fn in glob.glob('*prof'):
79 for n in 'program total_time total_alloc total_ticks initial_capabilities'.split():
85 ```python Collapsed="false"
86 performance = pd.DataFrame(profs).set_index('program').sort_index()
90 ```python Collapsed="false"
91 performance.total_ticks.plot.bar()
94 ```python Collapsed="false"
95 performance.total_ticks.plot.bar(logy=True)
98 ```python Collapsed="false"
99 performance.total_alloc.plot.bar()
102 ```python Collapsed="false"
103 performance.total_alloc.plot.bar(logy=True)
106 ```python Collapsed="false"
107 performance[['total_ticks', 'total_alloc']].plot.bar(
108 logy=True, secondary_y=['total_alloc'],
109 figsize=(8, 6), title="Internal time and memory")
110 plt.savefig('internal_time_and_memory_log.png')
113 ```python Collapsed="false"
114 performance[['total_ticks', 'total_alloc']].plot.bar(
115 logy=False, secondary_y=['total_alloc'],
116 figsize=(8, 6), title="Internal time and memory")
117 plt.savefig('internal_time_and_memory_linear.png')
121 # times = pd.read_csv('times.csv',
122 # names=['program', 'system', 'elapsed', 'memory'],
123 # index_col='program')
124 # times.index = times.index.str.slice(start=len('cabal run '))
125 # times.elapsed = pd.to_numeric(times.elapsed.str.slice(start=2))
130 today = datetime.date.today()
131 today = datetime.datetime(year=today.year, month=today.month, day=today.day) - datetime.timedelta(seconds=1)
136 epoch = datetime.datetime(year=1900, month=1, day=1)
141 times = pd.read_csv('times_raw.csv',
142 names=['program', 'system', 'elapsed', 'memory'],
144 times.elapsed = (pd.to_datetime(times.elapsed, format="%M:%S.%f") - epoch)
145 times.elapsed = times.elapsed.apply(lambda x: x.total_seconds())
153 ```python Collapsed="false"
157 ```python Collapsed="false"
158 performance = performance.merge(times, left_index=True, right_index=True)
159 # performance.drop(index='advent15loop', inplace=True)
163 ```python Collapsed="false"
168 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
169 performance.elapsed.plot.bar(
170 figsize=(8, 6), title="External time")
171 plt.savefig('external_time.png')
175 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
176 performance[['elapsed', 'memory']].plot.bar(
177 logy=False, secondary_y=['memory'],
178 figsize=(8, 6), title="External time and memory")
179 plt.savefig('external_time_and_memory.png')
183 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
184 performance[['elapsed', 'memory']].plot.bar(
185 logy=True, secondary_y=['memory'],
186 figsize=(8, 6), title="External time and memory")
187 plt.savefig('external_time_and_memory_log.png')
190 ```python Collapsed="false"
191 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
192 performance[['elapsed', 'memory']].plot.bar(
193 logy=False, secondary_y=['memory'],
194 figsize=(8, 6), title="External time and memory")
195 plt.savefig('external_time_and_memory_linear.png')
198 ```python Collapsed="false"
199 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
200 performance[['total_ticks', 'elapsed']].plot.bar(
201 logy=True, secondary_y=['elapsed'],
202 figsize=(8, 6), title="Internal vs external time")
203 plt.savefig('internal_external_time.png')
206 ```python Collapsed="false"
207 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
208 performance[['total_ticks', 'elapsed']].plot.bar(
209 logy=False, secondary_y=['elapsed'],
210 figsize=(8, 6), title="Internal vs external time")
211 plt.savefig('internal_external_time_linear.png')
214 ```python Collapsed="false"
215 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
216 performance[['total_alloc', 'memory']].plot.bar(
217 logy=True, secondary_y=['memory'],
218 figsize=(8, 6), title="Internal vs external memory")
219 plt.savefig('internal_external_memory_log.png')
222 ```python Collapsed="false"
223 # performance[['total_ticks', 'elapsed']].plot.bar(logy=True)
224 performance[['total_alloc', 'memory']].plot.bar(
225 logy=False, secondary_y=['memory'],
226 figsize=(8, 6), title="Internal vs external memory")
227 plt.savefig('internal_external_memory_linear.png')
230 ```python Collapsed="false"
231 # performance['elapsed_adj'] = performance['elapsed'] - 0.28
235 ```python Collapsed="false"
236 # performance[['total_time', 'elapsed_adj']].plot.bar(logy=True)
239 ```python Collapsed="false"
240 fig, ax = plt.subplots(ncols=3, figsize=(20,5))
242 performance['elapsed'].plot.bar(ax=ax[2],
244 title="Run times (wall clock), log scale",
247 ax[2].set_xlabel('Program')
249 performance['elapsed'].plot.bar(ax=ax[0],
251 title="Run times (wall clock), linear scale",
254 ax[0].set_xlabel('Program')
256 performance['elapsed'].plot.bar(ax=ax[1],
259 title="Run times (wall clock), truncated linear scale",
262 ax[1].set_xlabel('Program')
264 plt.savefig('run_times_combined.png')
267 ```python Collapsed="false"
268 fig, ax = plt.subplots(ncols=2, figsize=(13,5))
270 performance['memory'].plot.bar(ax=ax[0],
272 title="Memory used, log scale",
275 ax[0].set_xlabel('Program')
277 performance['memory'].plot.bar(ax=ax[1],
279 title="Memory used, linear scale",
282 ax[1].set_xlabel('Program')
284 plt.savefig('memory_combined.png')
288 fig, ax = plt.subplots(ncols=2, figsize=(13,5))
290 performance[['total_alloc', 'memory']].plot.bar(ax=ax[0],
291 logy=False, secondary_y=['memory'],
292 title="Internal vs external memory, linear scale")
293 ax[0].set_xlabel('Program')
295 performance[['total_alloc', 'memory']].plot.bar(ax=ax[1],
296 logy=True, secondary_y=['memory'],
297 title="Internal vs external memory. log scale")
299 plt.savefig('internal_external_memory_combined.png')
302 ```python Collapsed="false"
303 # ax = performance['elapsed_adj'].plot.bar(logy=False,
304 # title="Run times (wall clock), linear scale",
306 # ax.set_xlabel('Program')
307 # plt.savefig('run_times_linear.png')
310 ```python Collapsed="false"
314 ```python Collapsed="false"
315 performance['memory'].plot.bar()
318 ```python Collapsed="false"
319 performance.plot.scatter('elapsed', 'total_alloc', logx=True, logy=True)
322 ```python Collapsed="false"
323 performance.plot.scatter('memory', 'total_alloc', logx=True, logy=True)
326 ```python Collapsed="false"
327 performance.plot.scatter('elapsed', 'total_ticks', logx=True, logy=True)
330 ```python Collapsed="false"
331 performance[['total_alloc', 'memory', 'elapsed']].to_csv('performance.csv')
334 ```python Collapsed="false"
335 print(performance[['total_alloc', 'elapsed', 'memory']].to_markdown(floatfmt=['0.0f', '0.0f', '.2f', '0.0f']))
339 line_counts = ! find .. -path ../dist-newstyle -prune -o -type f -name "Main.hs" -exec wc -l {} \;
340 count_names = [re.search("(\d+) \.\./([^/]+)", l).groups([2, 1]) for l in line_counts if 'advent' in l if 'Main' in l]
341 program_counts = pd.Series({n: int(c) for n, c in sorted([(c, n) for n, c in count_names])})
346 program_counts[::-1].plot.barh(figsize=(6, 9))
347 plt.savefig('lines_of_code.png')
351 print(program_counts.to_markdown())
355 program_counts.median()