mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-30 11:56:25 +00:00
benchmarks
This commit is contained in:
parent
eb723f5112
commit
ad6ddf4f75
@ -1,5 +1,24 @@
|
||||
fn main() {
|
||||
// Part A
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_a(b: &mut Bencher) {
|
||||
b.iter(|| part_a());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_b(b: &mut Bencher) {
|
||||
b.iter(|| part_b());
|
||||
}
|
||||
}
|
||||
|
||||
fn part_a() {
|
||||
let result: u32 = include_str!("../input.txt")
|
||||
.trim()
|
||||
.split("\n\n")
|
||||
@ -8,3 +27,19 @@ fn main() {
|
||||
.unwrap();
|
||||
println!("A: {}", result);
|
||||
}
|
||||
|
||||
fn part_b() {
|
||||
let mut result: Vec<u32> = include_str!("../input.txt")
|
||||
.trim()
|
||||
.split("\n\n")
|
||||
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum::<u32>())
|
||||
.collect();
|
||||
result.sort();
|
||||
let total = &result.as_slice()[result.len() - 3..result.len()];
|
||||
println!("B: {:?}", total.iter().sum::<u32>());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
part_a();
|
||||
part_b();
|
||||
}
|
||||
|
@ -9,3 +9,5 @@ edition = "2021"
|
||||
[[bin]]
|
||||
name = "2022-01"
|
||||
path = "./2022/01/rust/main.rs"
|
||||
|
||||
# INJECT HERE
|
||||
|
38
README.md
38
README.md
@ -1,5 +1,37 @@
|
||||
# Advent Of Code
|
||||
|
||||
> New days are generated with [`hygen`](https://github.com/jondot/hygen).
|
||||
>
|
||||
> `bun run gen --year 2022 --day 1`
|
||||
## Getting started
|
||||
|
||||
New "days" are generated with [`hygen`](https://github.com/jondot/hygen). This will bootstrap code for python and rust. See details about the specifica languages below
|
||||
|
||||
```bash
|
||||
# First time setup
|
||||
bun i
|
||||
|
||||
# Generate
|
||||
bun run gen --year 2022 --day 1
|
||||
```
|
||||
|
||||
## Python
|
||||
|
||||
## Rust
|
||||
|
||||
Run a single day:
|
||||
|
||||
```bash
|
||||
cargo run --bin 2022-01
|
||||
```
|
||||
|
||||
Bench a day:
|
||||
|
||||
```bash
|
||||
cargo bench --bin 2022-01
|
||||
```
|
||||
|
||||
Bench all days:
|
||||
|
||||
```bash
|
||||
cargo bench
|
||||
```
|
||||
|
||||
> The benchmark is the built in Rust one. This is the [reason](https://doc.rust-lang.org/cargo/commands/cargo-bench.html) for the _nightly_ version.
|
||||
|
@ -2,8 +2,37 @@
|
||||
to: <%= dir %>/rust/main.rs
|
||||
unless_exists: true
|
||||
---
|
||||
fn main() {
|
||||
// Part A
|
||||
let contents = include_str!("../test.txt").trim();
|
||||
println!("A: {}", contents);
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_a(b: &mut Bencher) {
|
||||
b.iter(|| part_a());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_b(b: &mut Bencher) {
|
||||
b.iter(|| part_b());
|
||||
}
|
||||
}
|
||||
|
||||
fn part_a() {
|
||||
let result = include_str!("../input.txt");
|
||||
println!("A: {}", result);
|
||||
}
|
||||
|
||||
fn part_b() {
|
||||
let result = include_str!("../input.txt");
|
||||
println!("A: {}", result);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
part_a();
|
||||
part_b();
|
||||
}
|
||||
|
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
Loading…
Reference in New Issue
Block a user