From 6c706fae267ee6dd9ee466d9333a145d0bc3a029 Mon Sep 17 00:00:00 2001 From: Paul-Nicolas Madelaine Date: Mon, 27 Oct 2025 13:49:16 +0100 Subject: [PATCH] benches --- Cargo.lock | 265 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 12 ++ benches/benches.rs | 65 +++++++++++ 3 files changed, 342 insertions(+) create mode 100644 benches/benches.rs diff --git a/Cargo.lock b/Cargo.lock index fca901e..3c43bc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,271 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "btoi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b5ab9db53bcda568284df0fd39f6eac24ad6f7ba7ff1168b9e76eba6576b976" +dependencies = [ + "num-traits", +] + +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "eschac" version = "0.1.0" +dependencies = [ + "eschac 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gungraun", + "shakmaty", +] + +[[package]] +name = "eschac" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182f50cf07a29edc21b9d1173ce341949918c60a72dfa3a3ac1c644161f27fc" + +[[package]] +name = "gungraun" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b247b47ec86130ed355045982783d4666f32045e397a4547bbb6793cd53e940f" +dependencies = [ + "bincode", + "derive_more", + "gungraun-macros", + "gungraun-runner", +] + +[[package]] +name = "gungraun-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b605e561ccca36d68ebacd387751f2d58cf65202b781bb4a9029951dd3a66d" +dependencies = [ + "derive_more", + "proc-macro-error2", + "proc-macro2", + "quote", + "rustc_version", + "serde", + "serde_json", + "syn", +] + +[[package]] +name = "gungraun-runner" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0ae6c9fe670d3d77f5576be41568ebf1733e5873c6ca85ff3b85848a31ac76" +dependencies = [ + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "shakmaty" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0941d24adb219ae06d990af92633dea7486831ca00d6c3988c371e4e575035" +dependencies = [ + "arrayvec", + "bitflags", + "btoi", + "nohash-hasher", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" diff --git a/Cargo.toml b/Cargo.toml index 02f1792..83455cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,15 @@ keywords = ["chess"] [profile.dev] opt-level = 3 + +[profile.bench] +debug = true + +[[bench]] +name = "benches" +harness = false + +[dev-dependencies] +gungraun = "0.17" +shakmaty = "0.29" +eschac_prev = { package = "eschac", version = "0.1" } diff --git a/benches/benches.rs b/benches/benches.rs new file mode 100644 index 0000000..e055e70 --- /dev/null +++ b/benches/benches.rs @@ -0,0 +1,65 @@ +use eschac::position::Position; + +use gungraun::{main, library_benchmark_group, library_benchmark}; +use std::hint::black_box; + +static RECORDS: &'static [&'static str] = &[ + "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -", + "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -", + "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -", + "r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq -", + "rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ -", + "r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - -", +]; + +fn position(index: usize) -> Position { + Position::from_text_record(RECORDS[index - 1]).unwrap() +} +fn position_prev(index: usize) -> eschac_prev::position::Position { + eschac_prev::position::Position::from_text_record(RECORDS[index - 1]).unwrap() +} +fn position_shakmaty(index: usize) -> shakmaty::Chess { + RECORDS[index - 1].parse::().unwrap().into_position(shakmaty::CastlingMode::Standard).unwrap() +} + +#[library_benchmark] +#[bench::case_1(position(1), 4)] +#[bench::case_2(position(2), 4)] +#[bench::case_3(position(3), 4)] +#[bench::case_4(position(4), 4)] +#[bench::case_5(position(5), 4)] +#[bench::case_6(position(6), 4)] +fn perft(position: Position, depth: usize) -> u128 { + black_box(position.perft(depth)) +} + +#[library_benchmark] +#[bench::case_1(position_prev(1), 4)] +#[bench::case_2(position_prev(2), 4)] +#[bench::case_3(position_prev(3), 4)] +#[bench::case_4(position_prev(4), 4)] +#[bench::case_5(position_prev(5), 4)] +#[bench::case_6(position_prev(6), 4)] +fn perft_prev(position: eschac_prev::position::Position, depth: usize) -> u128 { + black_box(position.perft(depth)) +} + +#[library_benchmark] +#[bench::case_1(position_shakmaty(1), 4)] +#[bench::case_2(position_shakmaty(2), 4)] +#[bench::case_3(position_shakmaty(3), 4)] +#[bench::case_4(position_shakmaty(4), 4)] +#[bench::case_5(position_shakmaty(5), 4)] +#[bench::case_6(position_shakmaty(6), 4)] +fn perft_shakmaty(position: shakmaty::Chess, depth: usize) -> u128 { + black_box(shakmaty::perft(&position, depth as u32) as u128) +} + +library_benchmark_group!( + name = bench_eschac; + compare_by_id = true; + // benchmarks = perft_shakmaty, perft_prev, perft + benchmarks = perft, perft_prev +); + +main!(library_benchmark_groups = bench_eschac);