add benchmark for class / method calls (#4016)
This commit is contained in:
parent
74d9d23ba0
commit
22e8dd10e1
|
@ -11,6 +11,12 @@ impl EmptyClass {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
EmptyClass {}
|
EmptyClass {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn method(&self) {}
|
||||||
|
|
||||||
|
fn __len__(&self) -> usize {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is for demonstrating how to return a value from __next__
|
/// This is for demonstrating how to return a value from __next__
|
||||||
|
|
|
@ -8,14 +8,38 @@ def test_empty_class_init(benchmark):
|
||||||
benchmark(pyclasses.EmptyClass)
|
benchmark(pyclasses.EmptyClass)
|
||||||
|
|
||||||
|
|
||||||
|
def test_method_call(benchmark):
|
||||||
|
obj = pyclasses.EmptyClass()
|
||||||
|
assert benchmark(obj.method) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_proto_call(benchmark):
|
||||||
|
obj = pyclasses.EmptyClass()
|
||||||
|
assert benchmark(len, obj) == 0
|
||||||
|
|
||||||
|
|
||||||
class EmptyClassPy:
|
class EmptyClassPy:
|
||||||
|
def method(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __len__(self) -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def test_empty_class_init_py(benchmark):
|
def test_empty_class_init_py(benchmark):
|
||||||
benchmark(EmptyClassPy)
|
benchmark(EmptyClassPy)
|
||||||
|
|
||||||
|
|
||||||
|
def test_method_call_py(benchmark):
|
||||||
|
obj = EmptyClassPy()
|
||||||
|
assert benchmark(obj.method) == pyclasses.EmptyClass().method()
|
||||||
|
|
||||||
|
|
||||||
|
def test_proto_call_py(benchmark):
|
||||||
|
obj = EmptyClassPy()
|
||||||
|
assert benchmark(len, obj) == len(pyclasses.EmptyClass())
|
||||||
|
|
||||||
|
|
||||||
def test_iter():
|
def test_iter():
|
||||||
i = pyclasses.PyClassIter()
|
i = pyclasses.PyClassIter()
|
||||||
assert next(i) == 1
|
assert next(i) == 1
|
||||||
|
|
Loading…
Reference in New Issue