You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-43
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
6
6
7
7
<!--- advent_readme_stars table --->
8
8
9
+
<!--- benchmarking table --->
10
+
9
11
---
10
12
11
13
## Template setup
@@ -17,7 +19,7 @@ This template supports all major OS (macOS, Linux, Windows).
17
19
1. Open [the template repository](https://github.com/fspoettel/advent-of-code-rust) on Github.
18
20
2. Click [Use this template](https://github.com/fspoettel/advent-of-code-rust/generate) and create your repository.
19
21
3. Clone your repository to your computer.
20
-
4. If you are solving a previous year's aoc and want to use the `aoc-cli` integration, change the `AOC_YEAR` variable in `.cargo/config.toml` to reflect that.
22
+
4. If you are solving a previous year's advent of code, change the `AOC_YEAR` variable in `.cargo/config.toml` to reflect the year you are solving.
21
23
22
24
### Setup rust 💻
23
25
@@ -38,18 +40,18 @@ This template supports all major OS (macOS, Linux, Windows).
38
40
cargo scaffold <day>
39
41
40
42
# output:
41
-
# Created module "src/bin/01.rs"
42
-
# Created empty input file "src/inputs/01.txt"
43
-
# Created empty example file "src/examples/01.txt"
43
+
# Created module file "src/bin/01.rs"
44
+
# Created empty input file "data/inputs/01.txt"
45
+
# Created empty example file "data/examples/01.txt"
44
46
# ---
45
47
# 🎄 Type `cargo solve 01` to run your solution.
46
48
```
47
49
48
-
Individual solutions live in the `./src/bin/` directory as separate binaries.
50
+
Individual solutions live in the `./src/bin/` directory as separate binaries._Inputs_ and _examples_ live in the the `./data` directory.
49
51
50
-
Every [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/bin/scaffold.rs#L11-L41) has _unit tests_ referencing its _example_ file. Use these unit tests to develop and debug your solution against the example input. For some puzzles, it might be easier to forgo the example file and hardcode inputs into the tests.
52
+
Every [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/bin/scaffold.rs#L11-L41) has _unit tests_ referencing its _example_ file. Use these unit tests to develop and debug your solutions against the example input.
51
53
52
-
When editing a solution, `rust-analyzer` will display buttons for running / debugging unit tests above the unit test blocks.
54
+
Tip: when editing a solution, `rust-analyzer` will display buttons for running / debugging unit tests above the unit test blocks.
53
55
54
56
### Download input & description for a day
55
57
@@ -61,39 +63,32 @@ When editing a solution, `rust-analyzer` will display buttons for running / debu
61
63
cargo download <day>
62
64
63
65
# output:
64
-
# Loaded session cookie from "/Users/<snip>/.adventofcode.session".
65
-
# Fetching puzzle for day 1, 2022...
66
-
# Saving puzzle description to "src/puzzles/01.md"...
# [INFO aoc_client] 🎅 Saved puzzle to 'data/puzzles/01.md'
68
+
# [INFO aoc_client] 🎅 Saved input to 'data/inputs/01.txt'
70
69
# ---
71
-
# 🎄 Successfully wrote input to "src/inputs/01.txt".
72
-
# 🎄 Successfully wrote puzzle to "src/puzzles/01.md".
70
+
# 🎄 Successfully wrote input to "data/inputs/01.txt".
71
+
# 🎄 Successfully wrote puzzle to "data/puzzles/01.md".
73
72
```
74
73
75
-
Puzzle descriptions are stored in `src/puzzles` as markdown files. Puzzle inputs are not checked into git. [Reasoning](https://old.reddit.com/r/adventofcode/comments/k99rod/sharing_input_data_were_we_requested_not_to/gf2ukkf/?context=3).
76
-
77
74
### Run solutions for a day
78
75
79
76
```sh
80
77
# example: `cargo solve 01`
81
78
cargo solve <day>
82
79
83
80
# output:
81
+
# Finished dev [unoptimized + debuginfo] target(s) in 0.13s
84
82
# Running `target/debug/01`
85
-
# 🎄 Part 1 🎄
86
-
#
87
-
# 6 (elapsed: 37.03µs)
88
-
#
89
-
# 🎄 Part 2 🎄
90
-
#
91
-
# 9 (elapsed: 33.18µs)
83
+
# Part 1: 42 (166.0ns)
84
+
# Part 2: 42 (41.0ns)
92
85
```
93
86
94
-
`solve` is an alias for `cargo run --bin`. To run an optimized version for benchmarking, append the `--release` flag.
87
+
The `solve` command runs your solution. If you set the `--release` flag, real puzzle _inputs_ will be passed to your solution, otherwise the _example_ inputs will be used.
88
+
89
+
If you append the `--time` flag to the command, the runner will run your code between `10` and `10.000` times - depending on execution time of first execution - and print the average execution time.
95
90
96
-
Displayed _timings_ show the raw execution time of your solution without overhead (e.g. file reads).
91
+
For example, a benchmarked execution against real inputs of day 1 would look like `cargo solve 1 --release --time`. Displayed _timings_ show the raw execution time of your solution without overhead like file reads.
97
92
98
93
#### Submitting solutions
99
94
@@ -112,22 +107,21 @@ cargo all
112
107
# ----------
113
108
# | Day 01 |
114
109
# ----------
115
-
# 🎄 Part 1 🎄
116
-
#
117
-
# 0 (elapsed: 170.00µs)
118
-
#
119
-
# 🎄 Part 2 🎄
120
-
#
121
-
# 0 (elapsed: 30.00µs)
110
+
# Part 1: 42 (19.0ns)
111
+
# Part 2: 42 (19.0ns)
122
112
# <...other days...>
123
113
# Total: 0.20ms
124
114
```
125
115
126
-
`all` is an alias for `cargo run`. To run an optimized version for benchmarking, use the`--release`flag.
116
+
This runs all solutions sequentially and prints output to the command-line. Same as for the `solve` command,`--release`controls whether real inputs will be used.
127
117
128
-
_Total timing_ is computed from individual solution _timings_ and excludes as much overhead as possible.
118
+
#### Update readme benchmarks
129
119
130
-
### Run all solutions against the example input
120
+
The template can output a table with solution times to your readme. Please note that these are not "scientific" benchmarks, understand them as a fun approximation. 😉
121
+
122
+
In order to generate a benchmarking table, run `cargo all --release --time`. If everything goes well, the command will output "_Successfully updated README with benchmarks._" after the execution finishes.
123
+
124
+
### Run all tests
131
125
132
126
```sh
133
127
cargo test
@@ -148,6 +142,13 @@ cargo clippy
148
142
```
149
143
## Optional template features
150
144
145
+
### Download puzzle inputs via aoc-cli
146
+
147
+
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.12.0`
148
+
2. Create an `.adventofcode.session` file in your home directory and paste your session cookie. To get this, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in _Cookies_ under the _Application_ or _Storage_ tab, and copy out the `session` cookie value. [^1]
149
+
150
+
Once installed, you can use the [download command](#download-input--description-for-a-day).
151
+
151
152
### Read puzzle description in terminal
152
153
153
154
> **Note**
@@ -163,13 +164,6 @@ cargo read <day>
163
164
# ...the input...
164
165
```
165
166
166
-
### Download puzzle inputs via aoc-cli
167
-
168
-
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.12.0`
169
-
2. Create an `.adventofcode.session` file in your home directory and paste your session cookie[^1] into it. To get this, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in your Cookies under the Application or Storage tab, and copy out the `session` cookie value.
170
-
171
-
Once installed, you can use the [download command](#download-input--description-for-a-day).
172
-
173
167
### Check code formatting in CI
174
168
175
169
Uncomment the `format` job in the `ci.yml` workflow to enable fmt checks in CI.
0 commit comments