From 97d6075473b68d7f956da6a524e087ed44f49271 Mon Sep 17 00:00:00 2001 From: melkor Date: Sun, 21 Jan 2024 22:11:43 -0800 Subject: [PATCH] Update iai & refactor --- Cargo.toml | 2 +- benches/iai.rs | 109 ++++++++++++++----------------------------------- 2 files changed, 31 insertions(+), 80 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa94569..f4e1d33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ xxhash-rust = { version = "0.8", features = ["xxh3"] } [dev-dependencies] arrow2 = { version = "0.17", features = ["io_json"] } criterion = "0.5" -iai-callgrind = "0.9" +iai-callgrind = "0.10" pretty_assertions = "1.3" ssbm-data = "0.1" diff --git a/benches/iai.rs b/benches/iai.rs index c5f8fd4..c7228c8 100644 --- a/benches/iai.rs +++ b/benches/iai.rs @@ -1,103 +1,54 @@ use peppi::{ self, - io::slippi::de::{read, Opts}, + io::slippi::de::{self, Opts}, }; -use std::{fs::File, io::BufReader, path::PathBuf}; +use std::{hint::black_box, io::Cursor, path::PathBuf}; use iai_callgrind::{library_benchmark, library_benchmark_group, main}; -fn game(replay: &str, skip_frames: bool) { +fn read(replay: &str) -> Vec { let path = PathBuf::from(format!("benches/data/{}.slp", replay)); - let mut buf = BufReader::new(File::open(path).unwrap()); - read( - &mut buf, - Some(&Opts { - skip_frames, - ..Default::default() - }), - ) + std::fs::read(path).unwrap() } #[library_benchmark] -fn casual_doubles() { - game("casual_doubles", false) +#[benches::parse_full( + read("casual_doubles"), + read("hbox_llod_timeout_g8"), + read("ics_ditto"), + read("mango_zain_netplay"), + read("old_ver_thegang"), + read("short_game_tbh10") +)] +fn parse_full(buf: Vec) { + black_box(de::read(&mut Cursor::new(&buf[..]), None).unwrap()); } #[library_benchmark] -fn casual_doubles_skip_frames() { - game("casual_doubles", true) -} - -#[library_benchmark] -fn hbox_llod_timeout_g8() { - game("hbox_llod_timeout_g8", false) -} - -#[library_benchmark] -fn hbox_llod_timeout_g8_skip_frames() { - game("hbox_llod_timeout_g8", true) -} - -#[library_benchmark] -fn ics_ditto() { - game("ics_ditto", false) -} - -#[library_benchmark] -fn ics_ditto_skip_frames() { - game("ics_ditto", true) -} - -#[library_benchmark] -fn mango_zain_netplay() { - game("mango_zain_netplay", false) -} - -#[library_benchmark] -fn mango_zain_netplay_skip_frames() { - game("mango_zain_netplay", true) -} - -#[library_benchmark] -fn old_ver_thegang() { - game("old_ver_thegang", false) -} - -#[library_benchmark] -fn old_ver_thegang_skip_frames() { - game("old_ver_thegang", true) -} - -#[library_benchmark] -fn short_game_tbh10() { - game("short_game_tbh10", false) -} - -#[library_benchmark] -fn short_game_tbh10_skip_frames() { - game("short_game_tbh10", true) +#[benches::parse_skip_frames( + read("casual_doubles"), + read("hbox_llod_timeout_g8"), + read("ics_ditto"), + read("mango_zain_netplay"), + read("old_ver_thegang"), + read("short_game_tbh10") +)] +fn parse_skip_frames(buf: Vec) { + let opts = Opts { + skip_frames: true, + ..Default::default() + }; + black_box(de::read(&mut Cursor::new(&buf[..]), Some(&opts)).unwrap()); } library_benchmark_group!( name = full; - benchmarks = - casual_doubles, - hbox_llod_timeout_g8, - ics_ditto, - mango_zain_netplay, - old_ver_thegang, - short_game_tbh10 + benchmarks = parse_full ); library_benchmark_group!( name = skip_frames; - benchmarks = - casual_doubles_skip_frames, - hbox_llod_timeout_g8_skip_frames, - ics_ditto_skip_frames, - mango_zain_netplay_skip_frames, - old_ver_thegang_skip_frames, - short_game_tbh10_skip_frames + benchmarks = parse_skip_frames ); main!(library_benchmark_groups = full, skip_frames);