-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from calcit-lang/loop-get
Index with loop_get
- Loading branch information
Showing
6 changed files
with
362 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use im_ternary_tree::TernaryTreeList; | ||
|
||
const ITER_SIZE: usize = 10000; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("index", |b| { | ||
let mut data = TernaryTreeList::Empty; | ||
|
||
for idx in 0..ITER_SIZE { | ||
data = data.push(idx) | ||
} | ||
|
||
b.iter(|| { | ||
for idx in 0..ITER_SIZE { | ||
let _ = data[idx]; | ||
} | ||
}) | ||
}); | ||
|
||
c.bench_function("get", |b| { | ||
let mut data = TernaryTreeList::Empty; | ||
|
||
for idx in 0..ITER_SIZE { | ||
data = data.push(idx) | ||
} | ||
|
||
b.iter(|| { | ||
for idx in 0..ITER_SIZE { | ||
let _ = data.get(idx); | ||
} | ||
}) | ||
}); | ||
|
||
c.bench_function("loop_get", |b| { | ||
let mut data = TernaryTreeList::Empty; | ||
|
||
for idx in 0..ITER_SIZE { | ||
data = data.push(idx) | ||
} | ||
|
||
b.iter(|| { | ||
for idx in 0..ITER_SIZE { | ||
let _ = data.loop_get(idx); | ||
} | ||
}) | ||
}); | ||
|
||
c.bench_function("ref_get", |b| { | ||
let mut data = TernaryTreeList::Empty; | ||
|
||
for idx in 0..ITER_SIZE { | ||
data = data.push(idx) | ||
} | ||
|
||
b.iter(|| { | ||
for idx in 0..ITER_SIZE { | ||
let _ = data.ref_get(idx).to_owned(); | ||
} | ||
}) | ||
}); | ||
|
||
c.bench_function("first", |b| { | ||
let mut data = TernaryTreeList::Empty; | ||
|
||
for idx in 0..ITER_SIZE { | ||
data = data.push(idx) | ||
} | ||
|
||
b.iter(|| { | ||
for _ in 0..ITER_SIZE { | ||
let _ = data.first(); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.