diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c0eb987..b5e9d1c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -8,9 +8,9 @@ jobs: matrix: rust: - version: 1.58.1 - run-all: false + integration-tests: false - version: 1.80.1 - run-all: true + integration-tests: true steps: - uses: actions/checkout@v2 @@ -34,25 +34,24 @@ jobs: rustup default ${{ matrix.rust.version }} - name: Check lib - run: $HOME/.cargo/bin/cargo check --lib - - - name: Check all - # We can't use --all-targets because it includes benches which requires nightly compiler - run: $HOME/.cargo/bin/cargo check --workspace --lib --bins --examples --tests - if: ${{ matrix.rust.run-all }} - - - name: Clippy - # We can't use --all-targets because it includes benches which requires nightly compiler - run: $HOME/.cargo/bin/cargo clippy --workspace --lib --bins --examples --tests - if: ${{ matrix.rust.run-all }} - - - name: Check Format - run: $HOME/.cargo/bin/cargo fmt --check - if: ${{ matrix.rust.run-all }} + run: | + $HOME/.cargo/bin/cargo check --all-targets --no-default-features + $HOME/.cargo/bin/cargo check --all-targets + $HOME/.cargo/bin/cargo clippy --all-targets + $HOME/.cargo/bin/cargo fmt --check + $HOME/.cargo/bin/cargo test + env: + RUST_BACKTRACE: 1 - - name: Test - run: $HOME/.cargo/bin/cargo test --workspace - if: ${{ matrix.rust.run-all }} + - name: Check integration tests + run: | + pushd integration_tests + $HOME/.cargo/bin/cargo check --all-targets + $HOME/.cargo/bin/cargo clippy --all-targets + $HOME/.cargo/bin/cargo fmt --check + $HOME/.cargo/bin/cargo test + popd + if: ${{ matrix.rust.integration-tests }} env: RUST_BACKTRACE: 1 diff --git a/Cargo.lock b/Cargo.lock index f5cef51..80e22ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,72 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "bit-set" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf" - -[[package]] -name = "bitflags" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" - -[[package]] -name = "byteorder" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" - [[package]] name = "cfg-if" -version = "0.1.2" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" - -[[package]] -name = "dtoa" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5edd69c67b2f8e0911629b7e6b8a34cb3956613cd7c6e6414966dee349c2db4f" - -[[package]] -name = "fnv" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c5f769d0418837c08fc1fafc29a25baebe21b7eb4e3149db11c37a2019d74c" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b5365afd01fdf916e775a224e844f80b3b9710d0f4f00903e219e859474d7ae" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069def9a0e5feb7e9120635f6ebad24d853a6affbb077fec84d0888316cf9ae6" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "getrandom" @@ -80,77 +19,19 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "362385356d610bd1e5a408ddf8d022041774b683f345a1d2cfcb4f60f8ae2db5" - -[[package]] -name = "indexmap" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "intmap" version = "2.0.0" dependencies = [ - "indexmap", - "rand 0.8.5", + "rand", "serde", ] -[[package]] -name = "intmap-integration-test-random-ops" -version = "0.1.0" -dependencies = [ - "intmap", - "proptest", -] - -[[package]] -name = "intmap-integration-test-serde" -version = "0.1.0" -dependencies = [ - "intmap", - "proptest", - "serde_json", -] - -[[package]] -name = "itoa" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fd9dc2c587067de817fec4ad355e3818c3d893a78cab32a0a474c7a15bb8d5" - -[[package]] -name = "lazy_static" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" - [[package]] name = "libc" -version = "0.2.64" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74dfca3d9957906e8d1e6a0b641dc9a59848e793f1da2165889fd4f62d10d79c" - -[[package]] -name = "num-traits" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51eab148f171aefad295f8cece636fc488b9b392ef544da31ea4b8ef6b9e9c39" - -[[package]] -name = "num-traits" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "ppv-lite86" @@ -158,48 +39,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" -[[package]] -name = "proptest" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" -dependencies = [ - "bit-set", - "bitflags", - "byteorder", - "lazy_static", - "num-traits 0.2.2", - "quick-error 2.0.0", - "rand 0.8.5", - "rand_chacha", - "rand_xorshift", - "regex-syntax", - "rusty-fork", - "tempfile", -] - -[[package]] -name = "quick-error" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c36987d4978eb1be2e422b1e0423a557923a5c3e7e6f31d5699e9aafaefa469" - -[[package]] -name = "quick-error" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" - -[[package]] -name = "rand" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5f78082e6a6d042862611e9640cf20776185fee506cf6cf67e93c6225cee31" -dependencies = [ - "fuchsia-zircon", - "libc", -] - [[package]] name = "rand" version = "0.8.5" @@ -230,121 +69,14 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core", -] - -[[package]] -name = "redox_syscall" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35a48131ab10dbeb17202bd1dcb9c9798963a58a50c9ec31640f237358832094" - -[[package]] -name = "regex-syntax" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b" -dependencies = [ - "ucd-util", -] - -[[package]] -name = "remove_dir_all" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc5b3ce5d5ea144bb04ebd093a9e14e9765bcfec866aecda9b6dec43b3d1e24" -dependencies = [ - "winapi", -] - -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error 1.2.0", - "tempfile", - "wait-timeout", -] - [[package]] name = "serde" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "369633cfe0f0bde1dfc037fb6c5a329d46586a31f981bed14d87487a3439ae37" -[[package]] -name = "serde_json" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c62115693d0a9ed8c32d1c760f0fdbe7d4b05cb13c135b9b54137ac0d59fccb" -dependencies = [ - "dtoa", - "itoa", - "num-traits 0.1.32", - "serde", -] - -[[package]] -name = "tempfile" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47776f63b85777d984a50ce49d6b9e58826b6a3766a449fc95bc66cd5663c15b" -dependencies = [ - "libc", - "rand 0.4.1", - "redox_syscall", - "remove_dir_all", - "winapi", -] - -[[package]] -name = "ucd-util" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac9567e27ca9fc45bac22f987fd62547b0ac65d2e6502dfc09cdab7dbdba31f" - -[[package]] -name = "wait-timeout" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "winapi" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3ad91d846a4a5342c1fb7008d26124ee6cf94a3953751618577295373b32117" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a16a8e2ebfc883e2b1771c6482b1fb3c6831eab289ba391619a2d93a7356220f" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca29cb03c8ceaf20f8224a18a530938305e9872b1478ea24ff44b4f503a1d1d" diff --git a/Cargo.toml b/Cargo.toml index eb9104e..721500e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,6 @@ serde = { version = "1.0", optional = true, default-features = false } [dev-dependencies] rand = "0.8.5" -indexmap = "1.8.2" [package.metadata.docs.rs] features = ["serde"] - -[workspace] -resolver = "2" -members = [ - "integration_tests/random_ops", - "integration_tests/serde", -] diff --git a/benches/basic_bench.rs b/benches/basic_bench.rs deleted file mode 100644 index 190c5bb..0000000 --- a/benches/basic_bench.rs +++ /dev/null @@ -1,210 +0,0 @@ -#![feature(test)] - -extern crate intmap; -extern crate rand; -extern crate test; - -extern crate indexmap; - -use indexmap::IndexMap; -use intmap::IntMap; -use std::collections::HashMap; - -#[cfg(test)] -mod tests { - use super::*; - use intmap::Entry; - use test::Bencher; - - const VEC_COUNT: usize = 10_000; - - // ********** Built in ********** - - #[bench] - fn u64_insert_built_in(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map = HashMap::with_capacity(data.len()); - - b.iter(|| { - map.clear(); - - for s in data.iter() { - test::black_box(map.insert(s, s)); - } - }); - } - - #[bench] - fn u64_insert_built_in_without_capacity(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - - b.iter(|| { - let mut map = HashMap::new(); - - for s in data.iter() { - test::black_box(map.insert(s, s)); - } - - test::black_box(&map); - }); - } - - #[bench] - fn u64_get_built_in(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map: HashMap<&u64, &u64> = HashMap::with_capacity(data.len()); - - for s in data.iter() { - test::black_box(map.insert(s, s)); - } - - b.iter(|| { - for s in data.iter() { - test::black_box({ - map.contains_key(s); - }); - } - }); - } - - // ********** IndexMap ********** - - #[bench] - fn u64_insert_indexmap(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map = IndexMap::with_capacity(data.len()); - - b.iter(|| { - map.clear(); - - for s in data.iter() { - test::black_box(map.insert(s, s)); - } - }); - } - - #[bench] - fn u64_get_indexmap(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map: IndexMap<&u64, &u64> = IndexMap::with_capacity(data.len()); - - for s in data.iter() { - test::black_box(map.insert(s, s)); - } - - b.iter(|| { - for s in data.iter() { - test::black_box({ - map.contains_key(s); - }); - } - }); - } - - // ********** Intmap ********** - - #[bench] - fn u64_insert_intmap(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map = IntMap::with_capacity(data.len()); - - b.iter(|| { - map.clear(); - - for s in data.iter() { - test::black_box(map.insert(*s, s)); - } - }); - } - - #[bench] - fn u64_insert_intmap_checked(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - let mut map = IntMap::with_capacity(data.len()); - - b.iter(|| { - map.clear(); - - for s in data.iter() { - test::black_box(map.insert_checked(*s, s)); - } - }); - } - - #[bench] - fn u64_insert_intmap_entry(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - - let mut map = IntMap::with_capacity(data.len()); - - b.iter(|| { - map.clear(); - - for s in data.iter() { - test::black_box(match map.entry(*s) { - Entry::Occupied(_) => panic!("unexpected while insert, i = {}", s), - Entry::Vacant(entry) => entry.insert(s), - }); - } - }); - } - - #[bench] - fn u64_insert_intmap_without_capacity(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - - b.iter(|| { - let mut map = IntMap::new(); - - for s in data.iter() { - test::black_box(map.insert(*s, s)); - } - - test::black_box(&map); - }); - } - - #[bench] - fn u64_resize_intmap(b: &mut Bencher) { - b.iter(|| { - let mut map: IntMap = IntMap::new(); - map.reserve(VEC_COUNT); - test::black_box(&map); - }); - } - - #[bench] - fn u64_get_intmap(b: &mut Bencher) { - let data = get_random_range(VEC_COUNT); - - let mut map = IntMap::with_capacity(data.len()); - for s in data.iter() { - map.insert(*s, s); - } - - b.iter(|| { - for s in data.iter() { - test::black_box(map.contains_key(*s)); - } - }); - } - - // ********** Misc ********** - - fn get_random_range(count: usize) -> Vec { - use rand::prelude::StdRng; - use rand::{Rng, SeedableRng}; - - let mut vec = Vec::new(); - let mut rng = StdRng::seed_from_u64(4242); - - for _ in 0..count { - vec.push(rng.gen::()); - } - - vec.sort(); - vec.dedup(); - - vec - } -} diff --git a/integration_tests/Cargo.lock b/integration_tests/Cargo.lock new file mode 100644 index 0000000..f5c7434 --- /dev/null +++ b/integration_tests/Cargo.lock @@ -0,0 +1,637 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstyle", + "clap_lex", + "terminal_size", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + +[[package]] +name = "divan" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d567df2c9c2870a43f3f2bd65aaeb18dbce1c18f217c3e564b4fbaeb3ee56c" +dependencies = [ + "cfg-if", + "clap", + "condtype", + "divan-macros", + "libc", + "regex-lite", +] + +[[package]] +name = "divan-macros" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27540baf49be0d484d8f0130d7d8da3011c32a44d4fc873368154f1510e574a2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[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 = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "intmap" +version = "2.0.0" +dependencies = [ + "serde", +] + +[[package]] +name = "intmap-benchmark" +version = "0.1.0" +dependencies = [ + "divan", + "indexmap", + "intmap", + "rand", +] + +[[package]] +name = "intmap-integration-test-random-ops" +version = "0.1.0" +dependencies = [ + "intmap", + "proptest", +] + +[[package]] +name = "intmap-integration-test-serde" +version = "0.1.0" +dependencies = [ + "intmap", + "proptest", + "serde_json", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "lazy_static", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +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 = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustix" +version = "0.38.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[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 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml new file mode 100644 index 0000000..264ccee --- /dev/null +++ b/integration_tests/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] +resolver = "2" +members = [ + "benchmark", + "random_ops", + "serde", +] diff --git a/integration_tests/benchmark/Cargo.toml b/integration_tests/benchmark/Cargo.toml new file mode 100644 index 0000000..9b8d743 --- /dev/null +++ b/integration_tests/benchmark/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "intmap-integration-test-benchmark" +version = "0.1.0" +edition = "2021" +license = "MIT" +publish = false + +[dev-dependencies] +divan = "0.1.14" +indexmap = "1.8.2" +intmap = { path = "../.." } +rand = "0.8.5" + +[[bench]] +name = "basic_bench" +harness = false diff --git a/integration_tests/benchmark/benches/basic_bench.rs b/integration_tests/benchmark/benches/basic_bench.rs new file mode 100644 index 0000000..b9d15c0 --- /dev/null +++ b/integration_tests/benchmark/benches/basic_bench.rs @@ -0,0 +1,200 @@ +use divan::{bench, black_box, Bencher}; +use indexmap::IndexMap; +use intmap::{Entry, IntMap}; +use std::collections::HashMap; + +const VEC_COUNT: usize = 10_000; + +fn main() { + divan::main(); +} + +// ********** Built in ********** + +#[bench] +fn u64_insert_built_in(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map = HashMap::with_capacity(data.len()); + + bencher.bench_local(|| { + map.clear(); + + for s in data.iter() { + black_box(map.insert(s, s)); + } + }); +} + +#[bench] +fn u64_insert_built_in_without_capacity(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + + bencher.bench_local(|| { + let mut map = HashMap::new(); + + for s in data.iter() { + black_box(map.insert(s, s)); + } + + black_box(&map); + }); +} + +#[bench] +fn u64_get_built_in(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map: HashMap<&u64, &u64> = HashMap::with_capacity(data.len()); + + for s in data.iter() { + black_box(map.insert(s, s)); + } + + bencher.bench_local(|| { + for s in data.iter() { + black_box({ + map.contains_key(s); + }); + } + }); +} + +// ********** IndexMap ********** + +#[bench] +fn u64_insert_indexmap(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map = IndexMap::with_capacity(data.len()); + + bencher.bench_local(|| { + map.clear(); + + for s in data.iter() { + black_box(map.insert(s, s)); + } + }); +} + +#[bench] +fn u64_get_indexmap(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map: IndexMap<&u64, &u64> = IndexMap::with_capacity(data.len()); + + for s in data.iter() { + black_box(map.insert(s, s)); + } + + bencher.bench_local(|| { + for s in data.iter() { + black_box({ + map.contains_key(s); + }); + } + }); +} + +// ********** Intmap ********** + +#[bench] +fn u64_insert_intmap(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map = IntMap::with_capacity(data.len()); + + bencher.bench_local(|| { + map.clear(); + + for s in data.iter() { + black_box(map.insert(*s, s)); + } + }); +} + +#[bench] +fn u64_insert_intmap_checked(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + let mut map = IntMap::with_capacity(data.len()); + + bencher.bench_local(|| { + map.clear(); + + for s in data.iter() { + black_box(map.insert_checked(*s, s)); + } + }); +} + +#[bench] +fn u64_insert_intmap_entry(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + + let mut map = IntMap::with_capacity(data.len()); + + bencher.bench_local(|| { + map.clear(); + + for s in data.iter() { + black_box(match map.entry(*s) { + Entry::Occupied(_) => panic!("unexpected while insert, i = {}", s), + Entry::Vacant(entry) => entry.insert(s), + }); + } + }); +} + +#[bench] +fn u64_insert_intmap_without_capacity(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + + bencher.bench_local(|| { + let mut map = IntMap::new(); + + for s in data.iter() { + black_box(map.insert(*s, s)); + } + + black_box(&map); + }); +} + +#[bench] +fn u64_resize_intmap(bencher: Bencher) { + bencher.bench_local(|| { + let mut map: IntMap = IntMap::new(); + map.reserve(VEC_COUNT); + black_box(&map); + }); +} + +#[bench] +fn u64_get_intmap(bencher: Bencher) { + let data = get_random_range(VEC_COUNT); + + let mut map = IntMap::with_capacity(data.len()); + for s in data.iter() { + map.insert(*s, s); + } + + bencher.bench_local(|| { + for s in data.iter() { + black_box(map.contains_key(*s)); + } + }); +} + +// ********** Misc ********** + +fn get_random_range(count: usize) -> Vec { + use rand::prelude::StdRng; + use rand::{Rng, SeedableRng}; + + let mut vec = Vec::new(); + let mut rng = StdRng::seed_from_u64(4242); + + for _ in 0..count { + vec.push(rng.gen::()); + } + + vec.sort(); + vec.dedup(); + + vec +}