Skip to content

Commit 17db096

Browse files
committed
bench: Add tests for constructing various containers from iterator.
Both "bound" (like, length known) and "unbound" (length unknown) are tested. All of list, tuple, bytes, bytesarray offer approximately the same performance, with "unbound" case being 30 times slower.
1 parent e53d219 commit 17db096

8 files changed

Lines changed: 64 additions & 0 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = list(l)
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = list(map(lambda x: x, l))
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = tuple(l)
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = tuple(map(lambda x: x, l))
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = bytes(l)
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = bytes(map(lambda x: x, l))
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = bytearray(l)
7+
8+
bench.run(test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bench
2+
3+
def test(num):
4+
for i in iter(range(num//10000)):
5+
l = [0] * 1000
6+
l2 = bytearray(map(lambda x: x, l))
7+
8+
bench.run(test)

0 commit comments

Comments
 (0)