From 17db09650569609793061e83aded7039e39e81a7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 19 Jun 2014 21:44:33 +0300 Subject: [PATCH] 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. --- tests/bench/from_iter-1-list_bound.py | 8 ++++++++ tests/bench/from_iter-2-list_unbound.py | 8 ++++++++ tests/bench/from_iter-3-tuple_bound.py | 8 ++++++++ tests/bench/from_iter-4-tuple_unbound.py | 8 ++++++++ tests/bench/from_iter-5-bytes_bound.py | 8 ++++++++ tests/bench/from_iter-6-bytes_unbound.py | 8 ++++++++ tests/bench/from_iter-7-bytearray_bound.py | 8 ++++++++ tests/bench/from_iter-8-bytearray_unbound.py | 8 ++++++++ 8 files changed, 64 insertions(+) create mode 100644 tests/bench/from_iter-1-list_bound.py create mode 100644 tests/bench/from_iter-2-list_unbound.py create mode 100644 tests/bench/from_iter-3-tuple_bound.py create mode 100644 tests/bench/from_iter-4-tuple_unbound.py create mode 100644 tests/bench/from_iter-5-bytes_bound.py create mode 100644 tests/bench/from_iter-6-bytes_unbound.py create mode 100644 tests/bench/from_iter-7-bytearray_bound.py create mode 100644 tests/bench/from_iter-8-bytearray_unbound.py diff --git a/tests/bench/from_iter-1-list_bound.py b/tests/bench/from_iter-1-list_bound.py new file mode 100644 index 0000000000..d209daecc5 --- /dev/null +++ b/tests/bench/from_iter-1-list_bound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = list(l) + +bench.run(test) diff --git a/tests/bench/from_iter-2-list_unbound.py b/tests/bench/from_iter-2-list_unbound.py new file mode 100644 index 0000000000..be019c52fe --- /dev/null +++ b/tests/bench/from_iter-2-list_unbound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = list(map(lambda x: x, l)) + +bench.run(test) diff --git a/tests/bench/from_iter-3-tuple_bound.py b/tests/bench/from_iter-3-tuple_bound.py new file mode 100644 index 0000000000..7b7fa36c6e --- /dev/null +++ b/tests/bench/from_iter-3-tuple_bound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = tuple(l) + +bench.run(test) diff --git a/tests/bench/from_iter-4-tuple_unbound.py b/tests/bench/from_iter-4-tuple_unbound.py new file mode 100644 index 0000000000..7c7f134c85 --- /dev/null +++ b/tests/bench/from_iter-4-tuple_unbound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = tuple(map(lambda x: x, l)) + +bench.run(test) diff --git a/tests/bench/from_iter-5-bytes_bound.py b/tests/bench/from_iter-5-bytes_bound.py new file mode 100644 index 0000000000..b793a3207e --- /dev/null +++ b/tests/bench/from_iter-5-bytes_bound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = bytes(l) + +bench.run(test) diff --git a/tests/bench/from_iter-6-bytes_unbound.py b/tests/bench/from_iter-6-bytes_unbound.py new file mode 100644 index 0000000000..20aa556277 --- /dev/null +++ b/tests/bench/from_iter-6-bytes_unbound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = bytes(map(lambda x: x, l)) + +bench.run(test) diff --git a/tests/bench/from_iter-7-bytearray_bound.py b/tests/bench/from_iter-7-bytearray_bound.py new file mode 100644 index 0000000000..72001a05c7 --- /dev/null +++ b/tests/bench/from_iter-7-bytearray_bound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = bytearray(l) + +bench.run(test) diff --git a/tests/bench/from_iter-8-bytearray_unbound.py b/tests/bench/from_iter-8-bytearray_unbound.py new file mode 100644 index 0000000000..e2263b8ef9 --- /dev/null +++ b/tests/bench/from_iter-8-bytearray_unbound.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + for i in iter(range(num//10000)): + l = [0] * 1000 + l2 = bytearray(map(lambda x: x, l)) + +bench.run(test)