mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
tests/internal_bench/class_instance: Benchmark instantiation.
This commit adds tests to benchmark the performance of class instantiation. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
committed by
Damien George
parent
36ab1c2640
commit
6d09d3e76e
11
tests/internal_bench/class_instance-0-object.py
Normal file
11
tests/internal_bench/class_instance-0-object.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import bench
|
||||
|
||||
X = object
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
13
tests/internal_bench/class_instance-0.1-object-gc.py
Normal file
13
tests/internal_bench/class_instance-0.1-object-gc.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import bench
|
||||
import gc
|
||||
|
||||
X = object
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
gc.collect()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
13
tests/internal_bench/class_instance-1-empty.py
Normal file
13
tests/internal_bench/class_instance-1-empty.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
13
tests/internal_bench/class_instance-1.1-classattr.py
Normal file
13
tests/internal_bench/class_instance-1.1-classattr.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
x = 0
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
14
tests/internal_bench/class_instance-1.2-func.py
Normal file
14
tests/internal_bench/class_instance-1.2-func.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
def f(self):
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
15
tests/internal_bench/class_instance-1.3-empty-gc.py
Normal file
15
tests/internal_bench/class_instance-1.3-empty-gc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import bench
|
||||
import gc
|
||||
|
||||
|
||||
class X:
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
gc.collect()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
14
tests/internal_bench/class_instance-2-init.py
Normal file
14
tests/internal_bench/class_instance-2-init.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
14
tests/internal_bench/class_instance-2.1-init_super.py
Normal file
14
tests/internal_bench/class_instance-2.1-init_super.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
def __init__(self):
|
||||
return super().__init__()
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
14
tests/internal_bench/class_instance-2.2-new.py
Normal file
14
tests/internal_bench/class_instance-2.2-new.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
def __new__(cls):
|
||||
return super().__new__(cls)
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
14
tests/internal_bench/class_instance-3-del.py
Normal file
14
tests/internal_bench/class_instance-3-del.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
16
tests/internal_bench/class_instance-3.1-del-gc.py
Normal file
16
tests/internal_bench/class_instance-3.1-del-gc.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import bench
|
||||
import gc
|
||||
|
||||
|
||||
class X:
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
gc.collect()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
13
tests/internal_bench/class_instance-4-slots.py
Normal file
13
tests/internal_bench/class_instance-4-slots.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
__slots__ = ["x"]
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
13
tests/internal_bench/class_instance-4.1-slots5.py
Normal file
13
tests/internal_bench/class_instance-4.1-slots5.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import bench
|
||||
|
||||
|
||||
class X:
|
||||
__slots__ = ["a", "b", "c", "d", "x"]
|
||||
|
||||
|
||||
def test(num):
|
||||
for i in range(num // 5):
|
||||
x = X()
|
||||
|
||||
|
||||
bench.run(test)
|
||||
Reference in New Issue
Block a user