diff --git a/Cargo.lock b/Cargo.lock index a8a1cac..db43ea0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloca" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4" +dependencies = [ + "cc", +] + [[package]] name = "anes" version = "0.1.6" @@ -66,12 +75,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" + [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "bumpalo" version = "3.16.0" @@ -90,6 +111,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cc" +version = "1.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -169,6 +199,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "colorz" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc2a5df6ee18d52a36920c93a7736761c6fcffa72b9d960fd9133dd8d57c5184" +dependencies = [ + "supports-color", +] + [[package]] name = "criterion" version = "0.5.1" @@ -242,6 +281,22 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "getrandom" version = "0.2.15" @@ -253,6 +308,23 @@ dependencies = [ "wasi", ] +[[package]] +name = "glob-match" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985c9503b412198aa4197559e9a318524ebc4519c229bfa05a535828c950b9d" + +[[package]] +name = "goblin" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27c1b4369c2cd341b5de549380158b105a04c331be5db9110eef7b6d2742134" +dependencies = [ + "log", + "plain", + "scroll", +] + [[package]] name = "half" version = "2.4.1" @@ -286,6 +358,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "is_ci" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -322,6 +400,22 @@ version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" version = "0.4.22" @@ -355,6 +449,12 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "plotters" version = "0.3.7" @@ -497,6 +597,20 @@ dependencies = [ "criterion", "rand", "simdutf8", + "tango-bench", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", ] [[package]] @@ -514,6 +628,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scroll" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde" version = "1.0.210" @@ -546,6 +680,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simdutf8" version = "0.1.5" @@ -558,6 +698,16 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "supports-color" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" +dependencies = [ + "is-terminal", + "is_ci", +] + [[package]] name = "syn" version = "2.0.79" @@ -569,6 +719,60 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tango-bench" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257822358c6f206fed78bfe6369cf959063b0644d70f88df6b19f2dadc93423e" +dependencies = [ + "alloca", + "anyhow", + "clap", + "colorz", + "glob-match", + "goblin", + "libloading", + "log", + "num-traits", + "rand", + "scroll", + "tempfile", + "thiserror", +] + +[[package]] +name = "tempfile" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tinytemplate" version = "1.2.1" diff --git a/Cargo.toml b/Cargo.toml index c17d055..604a58d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,16 @@ rust-version = "1.74.1" [dev-dependencies] criterion = { version = "0.5.1", features = ["html_reports"] } rand = "0.8.5" +tango-bench = "0.6.0" [[bench]] name = "criterion" harness = false +[[bench]] +name = "tango" +harness = false + [profile.profiling] inherits = "release" debug = true diff --git a/benches/tango.rs b/benches/tango.rs new file mode 100644 index 0000000..862a61f --- /dev/null +++ b/benches/tango.rs @@ -0,0 +1,64 @@ +use std::io::Seek; + +use std::hint::black_box; +use tango_bench::{benchmark_fn, tango_benchmarks, tango_main, IntoBenchmarks}; + +use ripmors::*; + +fn ascii_benchmarks() -> impl IntoBenchmarks { + [ + benchmark_fn("encode_string_ascii", |b| { + let data = std::fs::read_to_string("1-original.txt").unwrap(); + b.iter(move || encode_string_ascii(black_box(data.as_bytes()))) + }), + benchmark_fn("encode_stream_ascii", |b| { + let mut f = std::fs::File::open("1-original.txt").unwrap(); + let mut devnull = std::fs::File::create("/dev/null").unwrap(); + b.iter(move || { + f.rewind().unwrap(); + encode_stream_ascii(&mut f, &mut devnull).unwrap(); + }) + }), + ] +} + +fn unicode_benchmarks() -> impl IntoBenchmarks { + [ + benchmark_fn("encode_string_unicode", |b| { + let data = std::fs::read_to_string("4-unicode.txt").unwrap(); + b.iter(move || encode_string(black_box(&data))) + }), + benchmark_fn("encode_stream_unicode", |b| { + let mut f = std::fs::File::open("4-unicode.txt").unwrap(); + let mut devnull = std::fs::File::create("/dev/null").unwrap(); + b.iter(move || { + f.rewind().unwrap(); + encode_stream(&mut f, &mut devnull).unwrap(); + }) + }), + ] +} + +fn decode_benchmarks() -> impl IntoBenchmarks { + [ + benchmark_fn("decode_string", |b| { + let data = std::fs::read_to_string("2-encoded.txt").unwrap(); + b.iter(move || decode_string(black_box(&data.as_bytes()), to_standard)) + }), + benchmark_fn("decode_stream", |b| { + let mut f = std::fs::File::open("2-encoded.txt").unwrap(); + let mut devnull = std::fs::File::create("/dev/null").unwrap(); + b.iter(move || { + f.rewind().unwrap(); + encode_stream(&mut f, &mut devnull).unwrap(); + }) + }), + ] +} + +tango_benchmarks!( + ascii_benchmarks(), + unicode_benchmarks(), + decode_benchmarks() +); +tango_main!(); diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..54bbe15 --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +fn main() { + // Needed by tango benchmarks + println!("cargo:rustc-link-arg-benches=-rdynamic"); + println!("cargo:rerun-if-changed=build.rs"); +}