From 8432c946d7be21e49586b23c5607520625f62a4d Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Thu, 21 Nov 2024 15:01:39 +0100 Subject: [PATCH] add a benchmark --- Cargo.lock | 543 ++++++++++++++++++++++++++++++++++++++- Cargo.toml | 10 +- benches/binary.rs | 200 ++++++++++++++ src/binary/error.rs | 10 - src/binary/timestamps.rs | 5 - src/lib.rs | 4 +- 6 files changed, 747 insertions(+), 25 deletions(-) create mode 100644 benches/binary.rs diff --git a/Cargo.lock b/Cargo.lock index b5e8a7e..76c9499 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,12 +57,187 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.5.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" + +[[package]] +name = "codspeed" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "450a0e9df9df1c154156f4344f99d8f6f6e69d0fc4de96ef6e2e68b2ec3bce97" +dependencies = [ + "colored", + "libc", + "serde_json", +] + +[[package]] +name = "codspeed-criterion-compat" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb1a6cb9c20e177fde58cdef97c1c7c9264eb1424fe45c4fccedc2fb078a569" +dependencies = [ + "codspeed", + "colored", + "criterion", +] + +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "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-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "equivalent" version = "1.0.1" @@ -68,6 +255,16 @@ dependencies = [ "wasi", ] +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.15.0" @@ -80,6 +277,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "humansize" version = "2.1.3" @@ -105,12 +308,47 @@ version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "leb128" version = "0.2.5" @@ -139,6 +377,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "memchr" version = "2.7.4" @@ -213,6 +457,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "parking_lot" version = "0.12.3" @@ -233,7 +483,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -242,12 +492,49 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "portable-atomic" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -338,6 +625,56 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.7" @@ -431,6 +768,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[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.2.0" @@ -501,9 +847,11 @@ checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" name = "test_results_parser" version = "0.5.1" dependencies = [ + "codspeed-criterion-compat", "indexmap", "pyo3", "quick-xml", + "rand", "regex", "rinja", "serde", @@ -552,6 +900,16 @@ dependencies = [ "syn", ] +[[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 = "unicase" version = "2.7.0" @@ -579,12 +937,77 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "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.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + [[package]] name = "watto" version = "0.1.0" @@ -595,34 +1018,113 @@ dependencies = [ "thiserror 1.0.65", ] +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -635,24 +1137,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -665,6 +1191,7 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] diff --git a/Cargo.toml b/Cargo.toml index 652b6f3..63e2e7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "test_results_parser" -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] [dependencies] pyo3 = "0.22.5" @@ -18,3 +18,11 @@ rinja = "0.3.4" watto = { version = "0.1.0", features = ["writer", "strings"] } indexmap = "2.6.0" thiserror = "2.0.3" + +[dev-dependencies] +criterion = { version = "2.7.2", package = "codspeed-criterion-compat" } +rand = { version = "0.8.5", features = ["small_rng"] } + +[[bench]] +name = "binary" +harness = false diff --git a/benches/binary.rs b/benches/binary.rs new file mode 100644 index 0000000..02baffa --- /dev/null +++ b/benches/binary.rs @@ -0,0 +1,200 @@ +use std::hint::black_box; + +use criterion::{criterion_group, criterion_main, Criterion}; +use rand::distributions::{Alphanumeric, DistString, Distribution, Uniform, WeightedIndex}; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; +use test_results_parser::binary::*; +use test_results_parser::{Outcome, Testrun}; + +criterion_group!( + benches, + create_and_serialize, + read_and_aggregate, + update_same, + update_different, + merge, + merge_rewrite, +); +criterion_main!(benches); + +const NUM_TESTS: usize = 100_000; +const NON_OVERLAP: usize = 10_000; +const DAY: u32 = 24 * 60 * 60; + +fn create_and_serialize(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + + c.bench_function("create_and_serialize", |b| { + b.iter(|| { + write_tests(&tests, 60, 0); + }) + }); +} + +fn read_and_aggregate(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + let buf = write_tests(&tests, 60, 0); + + c.bench_function("read_aggregation", |b| { + b.iter(|| { + let parsed = TestAnalytics::parse(&buf, 0).unwrap(); + for test in parsed.tests() { + let _name = black_box(test.name().unwrap()); + let _aggregates = black_box(test.get_aggregates(0..60)); + } + }) + }); +} + +fn update_same(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + let buf = write_tests(&tests, 60, 0); + randomize_test_data(rand, &mut tests); + + c.bench_function("update_same", |b| { + b.iter(|| { + let parsed = TestAnalytics::parse(&buf, 1).unwrap(); + let mut writer = TestAnalyticsWriter::from_existing_format(&parsed, 1).unwrap(); + for test in &tests { + writer.add_test_run(test); + } + + let mut buf = vec![]; + writer.serialize(&mut buf).unwrap(); + buf + }) + }); +} + +fn update_different(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + let buf = write_tests(&tests[..NUM_TESTS - NON_OVERLAP], 60, 0); + randomize_test_data(rand, &mut tests); + + c.bench_function("update_different", |b| { + b.iter(|| { + let parsed = TestAnalytics::parse(&buf, 1 * DAY).unwrap(); + let mut writer = TestAnalyticsWriter::from_existing_format(&parsed, 1 * DAY).unwrap(); + for test in &tests[NON_OVERLAP..] { + writer.add_test_run(test); + } + + let mut buf = vec![]; + writer.serialize(&mut buf).unwrap(); + buf + }) + }); +} + +fn merge(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + let buf_1 = write_tests(&tests[..NUM_TESTS - NON_OVERLAP], 60, 0); + randomize_test_data(rand, &mut tests); + let buf_2 = write_tests(&tests[NON_OVERLAP..], 60, 1 * DAY); + + c.bench_function("merge", |b| { + b.iter(|| { + let parsed_1 = TestAnalytics::parse(&buf_1, 1 * DAY).unwrap(); + let parsed_2 = TestAnalytics::parse(&buf_2, 1 * DAY).unwrap(); + let writer = TestAnalyticsWriter::merge(&parsed_1, &parsed_2, 1 * DAY).unwrap(); + + let mut buf = vec![]; + writer.serialize(&mut buf).unwrap(); + buf + }) + }); +} + +fn merge_rewrite(c: &mut Criterion) { + let mut rand = SmallRng::seed_from_u64(0); + let rand = &mut rand; + + let mut tests = create_random_testcases(rand, NUM_TESTS); + randomize_test_data(rand, &mut tests); + let buf_1 = write_tests(&tests[..NUM_TESTS - NON_OVERLAP], 60, 0); + randomize_test_data(rand, &mut tests); + let buf_2 = write_tests(&tests[NON_OVERLAP..], 60, 1 * DAY); + + c.bench_function("merge_rewrite", |b| { + b.iter(|| { + let parsed_1 = TestAnalytics::parse(&buf_1, 1 * DAY).unwrap(); + let parsed_2 = TestAnalytics::parse(&buf_2, 1 * DAY).unwrap(); + let mut writer = TestAnalyticsWriter::merge(&parsed_1, &parsed_2, 1 * DAY).unwrap(); + + writer.rewrite(60, Some(0)).unwrap(); + + let mut buf = vec![]; + writer.serialize(&mut buf).unwrap(); + buf + }) + }); +} + +fn write_tests(tests: &[Testrun], num_days: usize, timestamp: u32) -> Vec { + let mut writer = TestAnalyticsWriter::new(num_days, timestamp); + for test in tests { + writer.add_test_run(test); + } + + let mut buf = vec![]; + writer.serialize(&mut buf).unwrap(); + buf +} + +fn create_random_testcases(rand: &mut impl Rng, num_tests: usize) -> Vec { + let name_lens = Uniform::from(5usize..50); + + (0..num_tests) + .map(|_| { + let name_len = name_lens.sample(rand); + let name = Alphanumeric.sample_string(rand, name_len); + + Testrun { + name, + classname: "".into(), + duration: 0., + outcome: Outcome::Pass, + testsuite: "".into(), + failure_message: None, + filename: None, + build_url: None, + computed_name: None, + } + }) + .collect() +} + +fn randomize_test_data(rand: &mut impl Rng, tests: &mut [Testrun]) { + let durations = Uniform::from(0f64..10f64); + let outcomes = WeightedIndex::new([1000, 10, 20]).unwrap(); + + for test in tests { + test.duration = durations.sample(rand); + test.outcome = match outcomes.sample(rand) { + 0 => Outcome::Pass, + 1 => Outcome::Skip, + _ => Outcome::Failure, + }; + } +} diff --git a/src/binary/error.rs b/src/binary/error.rs index 340fbdd..4cbc65d 100644 --- a/src/binary/error.rs +++ b/src/binary/error.rs @@ -42,16 +42,6 @@ pub struct TestAnalyticsError { } impl TestAnalyticsError { - /// Creates a new [`TestAnalyticsError`] from a known kind of error as well as an - /// arbitrary error payload. - pub(crate) fn new(kind: TestAnalyticsErrorKind, source: E) -> Self - where - E: Into>, - { - let source = Some(source.into()); - Self { kind, source } - } - /// Returns the corresponding [`TestAnalyticsErrorKind`] for this error. pub fn kind(&self) -> TestAnalyticsErrorKind { self.kind diff --git a/src/binary/timestamps.rs b/src/binary/timestamps.rs index 0984049..7985794 100644 --- a/src/binary/timestamps.rs +++ b/src/binary/timestamps.rs @@ -3,11 +3,6 @@ use std::ops::Range; /// Seconds in a day. pub const DAY: u32 = 24 * 60 * 60; -/// Rounds the given unix-timestamp down to days. -pub fn round_timestamp_to_day(timestamp: u32) -> u32 { - timestamp / DAY * DAY -} - /// Calculates the offset (in days / indices) between /// the "saved" timestamp vs "now". pub fn offset_from_today(timestamp_saved: u32, timestamp_now: u32) -> isize { diff --git a/src/lib.rs b/src/lib.rs index 78b749e..ed951aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,14 @@ use pyo3::exceptions::PyException; use pyo3::prelude::*; -mod binary; +pub mod binary; mod compute_name; mod failure_message; mod junit; mod testrun; +pub use testrun::{Framework, Outcome, Testrun}; + pyo3::create_exception!(test_results_parser, ParserError, PyException); pyo3::create_exception!(test_results_parser, ComputeNameError, PyException);