Skip to content

Commit 6d09d3e

Browse files
AJMansfielddpgeorge
authored andcommitted
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>
1 parent 36ab1c2 commit 6d09d3e

13 files changed

Lines changed: 177 additions & 0 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import bench
2+
3+
X = object
4+
5+
6+
def test(num):
7+
for i in range(num // 5):
8+
x = X()
9+
10+
11+
bench.run(test)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import bench
2+
import gc
3+
4+
X = object
5+
6+
7+
def test(num):
8+
for i in range(num // 5):
9+
x = X()
10+
gc.collect()
11+
12+
13+
bench.run(test)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import bench
2+
3+
4+
class X:
5+
pass
6+
7+
8+
def test(num):
9+
for i in range(num // 5):
10+
x = X()
11+
12+
13+
bench.run(test)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import bench
2+
3+
4+
class X:
5+
x = 0
6+
7+
8+
def test(num):
9+
for i in range(num // 5):
10+
x = X()
11+
12+
13+
bench.run(test)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bench
2+
3+
4+
class X:
5+
def f(self):
6+
pass
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
13+
14+
bench.run(test)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import bench
2+
import gc
3+
4+
5+
class X:
6+
pass
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
gc.collect()
13+
14+
15+
bench.run(test)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bench
2+
3+
4+
class X:
5+
def __init__(self):
6+
pass
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
13+
14+
bench.run(test)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bench
2+
3+
4+
class X:
5+
def __init__(self):
6+
return super().__init__()
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
13+
14+
bench.run(test)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bench
2+
3+
4+
class X:
5+
def __new__(cls):
6+
return super().__new__(cls)
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
13+
14+
bench.run(test)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import bench
2+
3+
4+
class X:
5+
def __del__(self):
6+
pass
7+
8+
9+
def test(num):
10+
for i in range(num // 5):
11+
x = X()
12+
13+
14+
bench.run(test)

0 commit comments

Comments
 (0)