-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fa46d0
commit 1f7c1fc
Showing
20 changed files
with
198 additions
and
73 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
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
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 @@ | ||
[package] | ||
name = "pyo3-benches" | ||
version = "0.1.0" | ||
description = "In-tree benchmarks for the PyO3 project" | ||
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
pyo3 = { path = "../", features = ["auto-initialize"] } | ||
|
||
[dev-dependencies] | ||
criterion = "0.3.5" | ||
|
||
[[bench]] | ||
name = "bench_any" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_call" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_comparisons" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_err" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_decimal" | ||
harness = false | ||
required-features = ["pyo3/rust_decimal"] | ||
|
||
[[bench]] | ||
name = "bench_dict" | ||
harness = false | ||
required-features = ["pyo3/hashbrown"] | ||
|
||
[[bench]] | ||
name = "bench_frompyobject" | ||
harness = false | ||
required-features = ["pyo3/macros"] | ||
|
||
[[bench]] | ||
name = "bench_gil" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_list" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_pyclass" | ||
harness = false | ||
required-features = ["pyo3/macros"] | ||
|
||
[[bench]] | ||
name = "bench_pyobject" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_set" | ||
harness = false | ||
required-features = ["pyo3/hashbrown"] | ||
|
||
[[bench]] | ||
name = "bench_tuple" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_intern" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_extract" | ||
harness = false | ||
|
||
[workspace] |
File renamed without changes.
File renamed without changes.
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,70 @@ | ||
use criterion::{criterion_group, criterion_main, Bencher, Criterion}; | ||
|
||
use pyo3::{prelude::*, pyclass::CompareOp, Python}; | ||
|
||
#[pyclass] | ||
struct OrderedDunderMethods(i64); | ||
|
||
#[pymethods] | ||
impl OrderedDunderMethods { | ||
fn __lt__(&self, other: &Self) -> bool { | ||
self.0 < other.0 | ||
} | ||
|
||
fn __le__(&self, other: &Self) -> bool { | ||
self.0 <= other.0 | ||
} | ||
|
||
fn __eq__(&self, other: &Self) -> bool { | ||
self.0 == other.0 | ||
} | ||
|
||
fn __ne__(&self, other: &Self) -> bool { | ||
self.0 != other.0 | ||
} | ||
|
||
fn __gt__(&self, other: &Self) -> bool { | ||
self.0 > other.0 | ||
} | ||
|
||
fn __ge__(&self, other: &Self) -> bool { | ||
self.0 >= other.0 | ||
} | ||
} | ||
|
||
#[pyclass] | ||
#[derive(PartialEq, Eq, PartialOrd, Ord)] | ||
struct OrderedRichcmp(i64); | ||
|
||
#[pymethods] | ||
impl OrderedRichcmp { | ||
fn __richcmp__(&self, other: &Self, op: CompareOp) -> bool { | ||
op.matches(self.cmp(other)) | ||
} | ||
} | ||
|
||
fn bench_ordered_dunder_methods(b: &mut Bencher<'_>) { | ||
Python::with_gil(|py| { | ||
let obj1 = Py::new(py, OrderedDunderMethods(0)).unwrap().into_ref(py); | ||
let obj2 = Py::new(py, OrderedDunderMethods(1)).unwrap().into_ref(py); | ||
|
||
b.iter(|| obj2.gt(obj1).unwrap()); | ||
}); | ||
} | ||
|
||
fn bench_ordered_richcmp(b: &mut Bencher<'_>) { | ||
Python::with_gil(|py| { | ||
let obj1 = Py::new(py, OrderedRichcmp(0)).unwrap().into_ref(py); | ||
let obj2 = Py::new(py, OrderedRichcmp(1)).unwrap().into_ref(py); | ||
|
||
b.iter(|| obj2.gt(obj1).unwrap()); | ||
}); | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("ordered_dunder_methods", bench_ordered_dunder_methods); | ||
c.bench_function("ordered_richcmp", bench_ordered_richcmp); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.