-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_call.rs
53 lines (45 loc) · 1.05 KB
/
bench_call.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#![feature(test)]
extern crate test;
use pyo3::prelude::*;
use test::Bencher;
macro_rules! test_module {
($py:ident, $code:literal) => {
PyModule::from_code($py, indoc::indoc!($code), file!(), "test_module")
.expect("module creation failed")
};
}
#[bench]
fn bench_call_0(b: &mut Bencher) {
Python::with_gil(|py| {
let module = test_module!(
py,
r#"
def foo(): pass
"#
);
let foo = module.getattr("foo").unwrap();
b.iter(|| {
for _ in 0..1000 {
foo.call0().unwrap();
}
});
})
}
#[bench]
fn bench_call_method_0(b: &mut Bencher) {
Python::with_gil(|py| {
let module = test_module!(
py,
r#"
class Foo:
def foo(self): pass
"#
);
let foo = module.getattr("Foo").unwrap().call0().unwrap();
b.iter(|| {
for _ in 0..1000 {
foo.call_method0("foo").unwrap();
}
});
})
}