Solutions for Advent of Code in Rust
This is forked via the excellent fspoettel/advent-of-code-rust.
Day | Part 1 | Part 2 |
---|---|---|
Day 1 | 103.1µs |
184.0µs |
Day 2 | 183.7µs |
247.5µs |
Day 3 | 30.9µs |
31.1µs |
Day 4 | 396.9µs |
386.9µs |
Day 5 | 323.7µs |
825.0µs |
Day 6 | 745.3µs |
928.5ms |
Day 7 | 3.3ms |
1.3s |
Day 8 | 120.4µs |
249.6µs |
Day 9 | 1.1ms |
165.2ms |
Day 10 | 115.9µs |
108.7µs |
Day 11 | 379.1µs |
8.8ms |
Total: 2411.33ms
# example: `cargo solve 01`
cargo solve <day>
# output:
# Finished dev [unoptimized + debuginfo] target(s) in 0.13s
# Running `target/debug/01`
# Part 1: 42 (166.0ns)
# Part 2: 42 (41.0ns)
The solve
command runs your solution against real puzzle inputs. To run an optimized build of your code, append the
--release
flag as with any other rust program.
# example: `cargo time 8 --store`
cargo time <day> [--all] [--store]
# output:
# Day 08
# ------
# Part 1: 1 (39.0ns @ 10000 samples)
# Part 2: 2 (39.0ns @ 10000 samples)
#
# Total (Run): 0.00ms
#
# Stored updated benchmarks.
The cargo time
command allows you to benchmark your code and store timings in the readme. When benching, 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.
cargo time
has three modes of execution:
cargo time
without arguments incrementally benches solutions that do not have been stored in the readme yet and skips the rest.cargo time <day>
benches a single solution.cargo time --all
benches all solutions.
By default, cargo time
does not write to the readme. In order to do so, append the --store
flag:
cargo time --store
.
Please note that these are not scientific benchmarks, understand them as a fun approximation. 😉 Timings, especially in the microseconds range, might change a bit between invocations.
cargo test
To run tests for a specific day, append --bin <day>
, e.g. cargo test --bin 01
. You can further scope it down to a
specific part, e.g. cargo test --bin 01 part_one
.