diff --git a/2018/README.md b/2018/README.md index 9c74b9d..a40cf11 100644 --- a/2018/README.md +++ b/2018/README.md @@ -28,3 +28,11 @@ graph below. Can you guess which days had a large simulation? The code to produce this graph is included in the `other` directory, and should be compatible with most peoples repo set-ups, so you can share your pain. If it is not, please let me know. + +## Performance + +I benchmarked the performance of my implementations on stable rust +(1.31.1 at the time of writing). The logarithmic runtime graph looks as +follows: + +![Runtime by day](runtime.svg) diff --git a/2018/other/runtimes.py b/2018/other/runtimes.py new file mode 100755 index 0000000..8c8792f --- /dev/null +++ b/2018/other/runtimes.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import fileinput +import re +import numpy as np +import matplotlib.pyplot as plt + + +def parse_time(val): + val = val.replace(",", "") + return int(val) / 1e9 + + +def parse_input(): + matcher = re.compile(r"day(\d{2})::part(1|2) ... bench:(\s+)([0-9,]+) ns/iter \(\+/- ([0-9,]+)\)$") + results = np.zeros((25, 2, 2)) + for line in sorted(fileinput.input()): + match = matcher.search(line) + assert match + + day = int(match.group(1)) - 1 + part = int(match.group(2)) - 1 + time = parse_time(match.group(4)) + variance = parse_time(match.group(5)) + results[day, part, :] = [time, variance] + + return results + + +def main(): + results = parse_input() + _, ax = plt.subplots() + ax.set_yscale('log') + ax.set_xlabel('Day') + ax.set_ylabel('Runtime (s)') + ax.set_xticks(list(range(1, 26))) + + bottom = np.min(results) + + for i in range(results.shape[1]): + values = results[:, i, 0] + errors = results[:, i, 1] + pos = np.arange(len(values)) + 0.8 + 0.4 * i + ax.bar(pos, values, yerr=errors, align='center', width=0.4, + bottom=bottom) + + ax.legend(['Part 1', 'Part 2']) + + plt.savefig('runtime.svg') + + +if __name__ == '__main__': + main() diff --git a/2018/runtime.svg b/2018/runtime.svg new file mode 100644 index 0000000..c91f879 --- /dev/null +++ b/2018/runtime.svg @@ -0,0 +1,2220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +