From 67c4936e35f1c3cf3e3cbf04302dc23ff4f764ec Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 12 Dec 2022 03:02:01 -0500 Subject: benchmarking --- Cargo.lock | 429 ++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 18 ++- benches/2020.rs | 46 ++++++ benches/2021.rs | 110 +++++++++++++ benches/2022.rs | 58 +++++++ benches/helpers/mod.rs | 72 +++++++++ bin/stub-code | 4 + src/bin/2021/day25.rs | 2 +- 8 files changed, 734 insertions(+), 5 deletions(-) create mode 100644 benches/2020.rs create mode 100644 benches/2021.rs create mode 100644 benches/2022.rs create mode 100644 benches/helpers/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 75e8f4b..1a3573c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,9 @@ dependencies = [ "advent-of-code-ocr", "ahash", "anyhow", + "criterion", "once_cell", + "paste", "paw", "priority-queue", "regex", @@ -47,6 +49,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -85,12 +93,51 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "2.34.0" @@ -102,11 +149,111 @@ dependencies = [ "bitflags", "strsim", "term_size", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex", + "indexmap", + "textwrap 0.16.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap 3.2.23", + "criterion-plot", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + [[package]] name = "either" version = "1.8.0" @@ -124,6 +271,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.12.3" @@ -167,6 +320,21 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -179,18 +347,73 @@ version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + [[package]] name = "paw" version = "1.0.0" @@ -260,6 +483,34 @@ dependencies = [ "siphasher", ] +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + [[package]] name = "priority-queue" version = "1.3.0" @@ -327,6 +578,28 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "rayon" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "regex" version = "1.7.0" @@ -344,6 +617,58 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "siphasher" version = "0.3.10" @@ -362,7 +687,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "paw", "structopt-derive", @@ -412,6 +737,22 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "unicode-ident" version = "1.0.5" @@ -442,12 +783,87 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -464,6 +880,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index e7995c4..37cbdd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" authors = ["Jesse Luehrs "] edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] advent-of-code-ocr = "0.1.1" ahash = "0.8.2" @@ -15,3 +13,19 @@ paw = "1.0.0" priority-queue = "1.3.0" regex = "1.7.0" structopt = { version = "0.3.26", features = ["paw", "wrap_help"] } + +[dev-dependencies] +criterion = { version = "0.4.0", features = ["html_reports"] } +paste = "1.0.9" + +[[bench]] +name = "2020" +harness = false + +[[bench]] +name = "2021" +harness = false + +[[bench]] +name = "2022" +harness = false diff --git a/benches/2020.rs b/benches/2020.rs new file mode 100644 index 0000000..5135e5a --- /dev/null +++ b/benches/2020.rs @@ -0,0 +1,46 @@ +#[macro_use] +mod helpers; + +#[path = "../src/bin/2020/day1.rs"] +mod day1; +#[path = "../src/bin/2020/day2.rs"] +mod day2; +#[path = "../src/bin/2020/day3.rs"] +mod day3; +#[path = "../src/bin/2020/day4.rs"] +mod day4; +#[path = "../src/bin/2020/day5.rs"] +mod day5; +#[path = "../src/bin/2020/day6.rs"] +mod day6; +#[path = "../src/bin/2020/day7.rs"] +mod day7; +#[path = "../src/bin/2020/day8.rs"] +mod day8; +#[path = "../src/bin/2020/day9.rs"] +mod day9; +// NEXT MOD + +day!(2020, 1, day1); +day!(2020, 2, day2); +day!(2020, 3, day3); +day!(2020, 4, day4); +day!(2020, 5, day5); +day!(2020, 6, day6); +day!(2020, 7, day7); +day!(2020, 8, day8); +day!(2020, 9, day9); +// NEXT DAY + +criterion::criterion_main!( + bench_2020day1, + bench_2020day2, + bench_2020day3, + bench_2020day4, + bench_2020day5, + bench_2020day6, + bench_2020day7, + bench_2020day8, + bench_2020day9, + // NEXT GROUP +); diff --git a/benches/2021.rs b/benches/2021.rs new file mode 100644 index 0000000..a5e0cc8 --- /dev/null +++ b/benches/2021.rs @@ -0,0 +1,110 @@ +#[macro_use] +mod helpers; + +#[path = "../src/bin/2021/day1.rs"] +mod day1; +#[path = "../src/bin/2021/day10.rs"] +mod day10; +#[path = "../src/bin/2021/day11.rs"] +mod day11; +#[path = "../src/bin/2021/day12.rs"] +mod day12; +#[path = "../src/bin/2021/day13.rs"] +mod day13; +#[path = "../src/bin/2021/day14.rs"] +mod day14; +#[path = "../src/bin/2021/day15.rs"] +mod day15; +#[path = "../src/bin/2021/day16.rs"] +mod day16; +#[path = "../src/bin/2021/day17.rs"] +mod day17; +#[path = "../src/bin/2021/day18.rs"] +mod day18; +#[path = "../src/bin/2021/day19.rs"] +mod day19; +#[path = "../src/bin/2021/day2.rs"] +mod day2; +#[path = "../src/bin/2021/day20.rs"] +mod day20; +#[path = "../src/bin/2021/day21.rs"] +mod day21; +#[path = "../src/bin/2021/day22.rs"] +mod day22; +#[path = "../src/bin/2021/day23.rs"] +mod day23; +#[path = "../src/bin/2021/day24.rs"] +mod day24; +#[path = "../src/bin/2021/day25.rs"] +mod day25; +#[path = "../src/bin/2021/day3.rs"] +mod day3; +#[path = "../src/bin/2021/day4.rs"] +mod day4; +#[path = "../src/bin/2021/day5.rs"] +mod day5; +#[path = "../src/bin/2021/day6.rs"] +mod day6; +#[path = "../src/bin/2021/day7.rs"] +mod day7; +#[path = "../src/bin/2021/day8.rs"] +mod day8; +#[path = "../src/bin/2021/day9.rs"] +mod day9; +// NEXT MOD + +day!(2021, 1, day1); +day!(2021, 2, day2); +day!(2021, 3, day3); +day!(2021, 4, day4); +day!(2021, 5, day5); +day!(2021, 6, day6); +day!(2021, 7, day7); +day!(2021, 8, day8); +day!(2021, 9, day9); +day!(2021, 10, day10); +day!(2021, 11, day11); +day!(2021, 12, day12); +day!(2021, 13, day13); +day!(2021, 14, day14); +day!(2021, 15, day15); +day!(2021, 16, day16); +day!(2021, 17, day17); +day!(2021, 18, day18); +day!(2021, 19, day19); +day!(2021, 20, day20); +day!(2021, 21, day21); +day!(2021, 22, day22); +day!(2021, 23, day23); +day!(2021, 24, day24); +day!(2021, 25, day25); +// NEXT DAY + +criterion::criterion_main!( + bench_2021day1, + bench_2021day2, + bench_2021day3, + bench_2021day4, + bench_2021day5, + bench_2021day6, + bench_2021day7, + bench_2021day8, + bench_2021day9, + bench_2021day10, + bench_2021day11, + bench_2021day12, + bench_2021day13, + bench_2021day14, + bench_2021day15, + bench_2021day16, + bench_2021day17, + bench_2021day18, + bench_2021day19, + bench_2021day20, + bench_2021day21, + bench_2021day22, + bench_2021day23, + bench_2021day24, + bench_2021day25, + // NEXT GROUP +); diff --git a/benches/2022.rs b/benches/2022.rs new file mode 100644 index 0000000..b6ee3df --- /dev/null +++ b/benches/2022.rs @@ -0,0 +1,58 @@ +#[macro_use] +mod helpers; + +#[path = "../src/bin/2022/day1.rs"] +mod day1; +#[path = "../src/bin/2022/day10.rs"] +mod day10; +#[path = "../src/bin/2022/day11.rs"] +mod day11; +#[path = "../src/bin/2022/day12.rs"] +mod day12; +#[path = "../src/bin/2022/day2.rs"] +mod day2; +#[path = "../src/bin/2022/day3.rs"] +mod day3; +#[path = "../src/bin/2022/day4.rs"] +mod day4; +#[path = "../src/bin/2022/day5.rs"] +mod day5; +#[path = "../src/bin/2022/day6.rs"] +mod day6; +#[path = "../src/bin/2022/day7.rs"] +mod day7; +#[path = "../src/bin/2022/day8.rs"] +mod day8; +#[path = "../src/bin/2022/day9.rs"] +mod day9; +// NEXT MOD + +day!(2022, 1, day1); +day!(2022, 2, day2); +day!(2022, 3, day3); +day!(2022, 4, day4); +day!(2022, 5, day5); +day!(2022, 6, day6); +day!(2022, 7, day7); +day!(2022, 8, day8); +day!(2022, 9, day9); +day!(2022, 10, day10); +day!(2022, 11, day11); +day!(2022, 12, day12); +// NEXT DAY + +criterion::criterion_main!( + bench_2022day1, + bench_2022day2, + bench_2022day3, + bench_2022day4, + bench_2022day5, + bench_2022day6, + bench_2022day7, + bench_2022day8, + bench_2022day9, + bench_2022day10, + bench_2022day11, + bench_2022day12, + // NEXT GROUP +); diff --git a/benches/helpers/mod.rs b/benches/helpers/mod.rs new file mode 100644 index 0000000..7303ebf --- /dev/null +++ b/benches/helpers/mod.rs @@ -0,0 +1,72 @@ +macro_rules! day { + ($year:expr, $day:expr, $mod:ident) => { + paste::paste! { + #[allow(unused_must_use)] + fn [](c: &mut criterion::Criterion) { + c.bench_function( + &format!("{} day {} parse", $year, $day), + |b| { + b.iter_batched( + || advent_of_code::parse::data($year, $day).unwrap(), + |data| $mod::parse(criterion::black_box(data)), + criterion::BatchSize::PerIteration, + ) + } + ); + } + } + + paste::paste! { + #[allow(unused_must_use)] + fn [](c: &mut criterion::Criterion) { + c.bench_function( + &format!("{} day {} part 1", $year, $day), + |b| { + b.iter_batched( + || { + $mod::parse( + advent_of_code::parse::data($year, $day) + .unwrap(), + ) + .unwrap() + }, + |data| $mod::part1(criterion::black_box(data)), + criterion::BatchSize::PerIteration, + ) + } + ); + } + } + + paste::paste! { + #[allow(unused_must_use)] + fn [](c: &mut criterion::Criterion) { + c.bench_function( + &format!("{} day {} part 2", $year, $day), + |b| { + b.iter_batched( + || { + $mod::parse( + advent_of_code::parse::data($year, $day) + .unwrap(), + ) + .unwrap() + }, + |data| $mod::part2(criterion::black_box(data)), + criterion::BatchSize::PerIteration, + ) + } + ); + } + } + + paste::paste! { + criterion::criterion_group!( + [], + [], + [], + [], + ); + } + }; +} diff --git a/bin/stub-code b/bin/stub-code index 6e91995..73d17eb 100755 --- a/bin/stub-code +++ b/bin/stub-code @@ -39,3 +39,7 @@ EOF perl -pi -E"\$seen_mod = 1 if /mod day$day;/; if (!\$seen_mod && /NEXT MOD/) { say 'mod day$day;'; }" src/bin/"$year"/main.rs perl -pi -E"\$seen_part = 1 if /day!.*day$day\)/; if (!\$seen_part && /NEXT PART/) { say ' $day => advent_of_code::day!($year, opt.day, opt.puzzle, day$day),'; }" src/bin/"$year"/main.rs + +perl -pi -E"\$seen_mod = 1 if /mod day$day;/; if (!\$seen_mod && /NEXT MOD/) { say '#[path = \"../src/bin/$year/day${day}.rs\"]'; say 'mod day$day;'; }" benches/"$year".rs +perl -pi -E"\$seen_day = 1 if /day!.*day$day\)/; if (!\$seen_day && /NEXT DAY/) { say 'day!($year, $day, day$day);'; }" benches/"$year".rs +perl -pi -E"\$seen_group = 1 if /bench_${year}day${day},/; if (!\$seen_group && /NEXT GROUP/) { say ' bench_${year}day$day,'; }" benches/"$year".rs diff --git a/src/bin/2021/day25.rs b/src/bin/2021/day25.rs index 68d866e..4bd5c92 100644 --- a/src/bin/2021/day25.rs +++ b/src/bin/2021/day25.rs @@ -84,7 +84,7 @@ pub fn part1(map: Map) -> Result { } pub fn part2(_: Map) -> Result { - todo!() + Ok(0) } #[test] -- cgit v1.2.3-54-g00ecf