Skip to content

Commit

Permalink
Merge pull request #1666 from davidhewitt/bench-new-containers
Browse files Browse the repository at this point in the history
benches: add benchmarks for container creation
  • Loading branch information
messense authored Jun 6, 2021
2 parents f9a3da3 + d6437af commit abd2588
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions benches/bench_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ fn iter_dict(b: &mut Bencher) {
});
}

fn dict_new(b: &mut Bencher) {
let gil = Python::acquire_gil();
let py = gil.python();
const LEN: usize = 50_000;
b.iter(|| (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict(py));
}

fn dict_get_item(b: &mut Bencher) {
let gil = Python::acquire_gil();
let py = gil.python();
Expand Down Expand Up @@ -58,6 +65,7 @@ fn extract_hashbrown_map(b: &mut Bencher) {

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("iter_dict", iter_dict);
c.bench_function("dict_new", dict_new);
c.bench_function("dict_get_item", dict_get_item);
c.bench_function("extract_hashmap", extract_hashmap);
c.bench_function("extract_btreemap", extract_btreemap);
Expand Down
8 changes: 8 additions & 0 deletions benches/bench_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ fn iter_list(b: &mut Bencher) {
});
}

fn list_new(b: &mut Bencher) {
let gil = Python::acquire_gil();
let py = gil.python();
const LEN: usize = 50_000;
b.iter(|| PyList::new(py, 0..LEN));
}

fn list_get_item(b: &mut Bencher) {
let gil = Python::acquire_gil();
let py = gil.python();
Expand All @@ -32,6 +39,7 @@ fn list_get_item(b: &mut Bencher) {

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("iter_list", iter_list);
c.bench_function("list_new", list_new);
c.bench_function("list_get_item", list_get_item);
}

Expand Down

0 comments on commit abd2588

Please sign in to comment.