aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAria <me@aria.rip>2023-10-05 15:15:41 +0100
committerAria <me@aria.rip>2023-10-05 15:15:41 +0100
commitc07742a053671908003a6300b2a64e715cadd6ad (patch)
tree07960d3e5b441d8d5507e8e993fbaa727c098036
parent1a8fba28d02a8415118e22f6d3816264b3840c95 (diff)
update primrose to rust 2021
-rw-r--r--primrose/Cargo.toml2
-rw-r--r--primrose/benches/criterion_benchmark.rs215
2 files changed, 116 insertions, 101 deletions
diff --git a/primrose/Cargo.toml b/primrose/Cargo.toml
index 21b2ef6..df92b05 100644
--- a/primrose/Cargo.toml
+++ b/primrose/Cargo.toml
@@ -2,7 +2,7 @@
name = "primrose"
version = "0.1.0"
authors = ["Xueying Qin <qinxy1995@gmail.com>"]
-edition = "2018"
+edition = "2021"
default-run = "main"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/primrose/benches/criterion_benchmark.rs b/primrose/benches/criterion_benchmark.rs
index cb4c649..6f47d95 100644
--- a/primrose/benches/criterion_benchmark.rs
+++ b/primrose/benches/criterion_benchmark.rs
@@ -1,18 +1,19 @@
-use criterion::{black_box, criterion_group, criterion_main, Criterion};
-use std::time::Duration;
-use std::mem::size_of;
-use std::collections::{BTreeSet, HashSet};
-use std::vec::Vec;
-use preprocess::traits::{Container};
-use preprocess::library::eager_unique_vector::{EagerUniqueVec};
-use preprocess::library::lazy_unique_vector::{LazyUniqueVec};
-use rand::{Rng,SeedableRng};
+use criterion::{criterion_group, criterion_main, Criterion};
+
+use primrose::library::lazy_unique_vector::LazyUniqueVec;
+use primrose::traits::Container;
use rand::rngs::StdRng;
use rand::seq::SliceRandom;
-use rand::thread_rng;
-// one search at the
-fn gen_dataset_1() -> Vec<u32> { // avoid duplication
+use rand::{SeedableRng};
+use std::collections::{BTreeSet, HashSet};
+use std::mem::size_of;
+
+use std::vec::Vec;
+
+// one search at the
+fn gen_dataset_1() -> Vec<u32> {
+ // avoid duplication
let size = 1024 * 1024; // 1 MB
let amount = size / size_of::<u32>();
let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication
@@ -21,7 +22,8 @@ fn gen_dataset_1() -> Vec<u32> { // avoid duplication
data
}
-fn gen_dataset_128() -> Vec<u32> { // avoid duplication
+fn gen_dataset_128() -> Vec<u32> {
+ // avoid duplication
let size = 128 * 1024 * 1024; // 128 MB
let amount = size / size_of::<u32>();
let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication
@@ -30,7 +32,8 @@ fn gen_dataset_128() -> Vec<u32> { // avoid duplication
data
}
-fn gen_dataset_256() -> Vec<u32> { // avoid duplication
+fn gen_dataset_256() -> Vec<u32> {
+ // avoid duplication
let size = 256 * 1024 * 1024; // 256 MB
let amount = size / size_of::<u32>();
let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication
@@ -39,7 +42,8 @@ fn gen_dataset_256() -> Vec<u32> { // avoid duplication
data
}
-fn gen_dataset_512() -> Vec<u32> { // avoid duplication
+fn gen_dataset_512() -> Vec<u32> {
+ // avoid duplication
let size = 512 * 1024 * 1024; // 512 MB
let amount = size / size_of::<u32>();
let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication
@@ -51,148 +55,159 @@ fn gen_dataset_512() -> Vec<u32> { // avoid duplication
fn btreeset_insertion_1m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut BTreeSet::new();
let data = gen_dataset_1();
- c.bench_function("btreeset insertion 1MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("btreeset insertion 1MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn btreeset_insertion_128m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut BTreeSet::new();
let data = gen_dataset_128();
- c.bench_function("btreeset insertion 128MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("btreeset insertion 128MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn btreeset_insertion_256m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut BTreeSet::new();
let data = gen_dataset_256();
- c.bench_function("btreeset insertion 256MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("btreeset insertion 256MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn btreeset_insertion_512m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut BTreeSet::new();
let data = gen_dataset_512();
- c.bench_function("btreeset insertion 512MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("btreeset insertion 512MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn hashset_insertion_1m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut HashSet::new();
let data = gen_dataset_1();
- c.bench_function("hashset insertion 1MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("hashset insertion 1MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn hashset_insertion_128m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut HashSet::new();
let data = gen_dataset_128();
- c.bench_function("hashset insertion 128MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("hashset insertion 128MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn hashset_insertion_256m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut HashSet::new();
let data = gen_dataset_256();
- c.bench_function("hashset insertion 256MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("hashset insertion 256MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn hashset_insertion_512m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut HashSet::new();
let data = gen_dataset_512();
- c.bench_function("hashset insertion 512MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("hashset insertion 512MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn lazy_uniuqe_vec_insertion_1m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new();
let data = gen_dataset_1();
- c.bench_function("lazy unique vector insertion 1MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("lazy unique vector insertion 1MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn lazy_uniuqe_vec_insertion_128m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new();
let data = gen_dataset_128();
- c.bench_function("lazy unique vector insertion 128MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("lazy unique vector insertion 128MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn lazy_uniuqe_vec_insertion_256m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new();
let data = gen_dataset_256();
- c.bench_function("lazy unique vector insertion 256MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("lazy unique vector insertion 256MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
fn lazy_uniuqe_vec_insertion_512m(c: &mut Criterion) {
let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new();
let data = gen_dataset_512();
- c.bench_function("lazy unique vector insertion 512MB", |b| b.iter(|| {
- for val in data.iter() {
- s.insert(*val);
- }
- s.contains(&1024);
- }
- ));
+ c.bench_function("lazy unique vector insertion 512MB", |b| {
+ b.iter(|| {
+ for val in data.iter() {
+ s.insert(*val);
+ }
+ s.contains(&1024);
+ })
+ });
}
-
criterion_group! {
name = insertion_1m;
config = Criterion::default().sample_size(10);