From d86fb670e6d78ca38dbaedfdde35180e3b8f4bb3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 18 Jun 2019 23:44:16 +1000 Subject: tests: Rename "bench" tests to "internal_bench" and run-internalbench.py To emphasise these benchmark tests compare the internal performance of features amongst themselves, rather than absolute performance testing. --- tests/bench/arrayop-1-list_inplace.py | 12 --- tests/bench/arrayop-2-list_map.py | 12 --- tests/bench/arrayop-3-bytearray_inplace.py | 12 --- tests/bench/arrayop-4-bytearray_map.py | 12 --- tests/bench/bench.py | 10 --- tests/bench/bytealloc-1-bytes_n.py | 7 -- tests/bench/bytealloc-2-repeat.py | 7 -- tests/bench/bytebuf-1-inplace.py | 11 --- tests/bench/bytebuf-2-join_map_bytes.py | 12 --- tests/bench/bytebuf-3-bytarray_map.py | 10 --- 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 -- tests/bench/func_args-1.1-pos_1.py | 10 --- tests/bench/func_args-1.2-pos_3.py | 10 --- tests/bench/func_args-2-pos_default_2_of_3.py | 10 --- tests/bench/func_args-3.1-kw_1.py | 10 --- tests/bench/func_args-3.2-kw_3.py | 10 --- tests/bench/func_builtin-1-enum_pos.py | 7 -- tests/bench/func_builtin-2-enum_kw.py | 7 -- tests/bench/funcall-1-inline.py | 9 -- tests/bench/funcall-2-funcall.py | 12 --- tests/bench/funcall-3-funcall-local.py | 16 ---- tests/bench/loop_count-1-range.py | 7 -- tests/bench/loop_count-2-range_iter.py | 7 -- tests/bench/loop_count-3-while_up.py | 8 -- tests/bench/loop_count-4-while_down_gt.py | 7 -- tests/bench/loop_count-5-while_down_ne.py | 7 -- .../bench/loop_count-5.1-while_down_ne_localvar.py | 8 -- tests/bench/var-1-constant.py | 8 -- tests/bench/var-2-global.py | 10 --- tests/bench/var-3-local.py | 10 --- tests/bench/var-4-arg.py | 9 -- tests/bench/var-5-class-attr.py | 11 --- tests/bench/var-6-instance-attr.py | 14 ---- tests/bench/var-6.1-instance-attr-5.py | 18 ---- tests/bench/var-7-instance-meth.py | 17 ---- tests/bench/var-8-namedtuple-1st.py | 12 --- tests/bench/var-8.1-namedtuple-5th.py | 12 --- tests/internal_bench/arrayop-1-list_inplace.py | 12 +++ tests/internal_bench/arrayop-2-list_map.py | 12 +++ .../internal_bench/arrayop-3-bytearray_inplace.py | 12 +++ tests/internal_bench/arrayop-4-bytearray_map.py | 12 +++ tests/internal_bench/bench.py | 10 +++ tests/internal_bench/bytealloc-1-bytes_n.py | 7 ++ tests/internal_bench/bytealloc-2-repeat.py | 7 ++ tests/internal_bench/bytebuf-1-inplace.py | 11 +++ tests/internal_bench/bytebuf-2-join_map_bytes.py | 12 +++ tests/internal_bench/bytebuf-3-bytarray_map.py | 10 +++ tests/internal_bench/from_iter-1-list_bound.py | 8 ++ tests/internal_bench/from_iter-2-list_unbound.py | 8 ++ tests/internal_bench/from_iter-3-tuple_bound.py | 8 ++ tests/internal_bench/from_iter-4-tuple_unbound.py | 8 ++ tests/internal_bench/from_iter-5-bytes_bound.py | 8 ++ tests/internal_bench/from_iter-6-bytes_unbound.py | 8 ++ .../internal_bench/from_iter-7-bytearray_bound.py | 8 ++ .../from_iter-8-bytearray_unbound.py | 8 ++ tests/internal_bench/func_args-1.1-pos_1.py | 10 +++ tests/internal_bench/func_args-1.2-pos_3.py | 10 +++ .../func_args-2-pos_default_2_of_3.py | 10 +++ tests/internal_bench/func_args-3.1-kw_1.py | 10 +++ tests/internal_bench/func_args-3.2-kw_3.py | 10 +++ tests/internal_bench/func_builtin-1-enum_pos.py | 7 ++ tests/internal_bench/func_builtin-2-enum_kw.py | 7 ++ tests/internal_bench/funcall-1-inline.py | 9 ++ tests/internal_bench/funcall-2-funcall.py | 12 +++ tests/internal_bench/funcall-3-funcall-local.py | 16 ++++ tests/internal_bench/loop_count-1-range.py | 7 ++ tests/internal_bench/loop_count-2-range_iter.py | 7 ++ tests/internal_bench/loop_count-3-while_up.py | 8 ++ tests/internal_bench/loop_count-4-while_down_gt.py | 7 ++ tests/internal_bench/loop_count-5-while_down_ne.py | 7 ++ .../loop_count-5.1-while_down_ne_localvar.py | 8 ++ tests/internal_bench/var-1-constant.py | 8 ++ tests/internal_bench/var-2-global.py | 10 +++ tests/internal_bench/var-3-local.py | 10 +++ tests/internal_bench/var-4-arg.py | 9 ++ tests/internal_bench/var-5-class-attr.py | 11 +++ tests/internal_bench/var-6-instance-attr.py | 14 ++++ tests/internal_bench/var-6.1-instance-attr-5.py | 18 ++++ tests/internal_bench/var-7-instance-meth.py | 17 ++++ tests/internal_bench/var-8-namedtuple-1st.py | 12 +++ tests/internal_bench/var-8.1-namedtuple-5th.py | 12 +++ tests/run-bench-tests | 97 ---------------------- tests/run-internalbench.py | 97 ++++++++++++++++++++++ 90 files changed, 532 insertions(+), 532 deletions(-) delete mode 100644 tests/bench/arrayop-1-list_inplace.py delete mode 100644 tests/bench/arrayop-2-list_map.py delete mode 100644 tests/bench/arrayop-3-bytearray_inplace.py delete mode 100644 tests/bench/arrayop-4-bytearray_map.py delete mode 100644 tests/bench/bench.py delete mode 100644 tests/bench/bytealloc-1-bytes_n.py delete mode 100644 tests/bench/bytealloc-2-repeat.py delete mode 100644 tests/bench/bytebuf-1-inplace.py delete mode 100644 tests/bench/bytebuf-2-join_map_bytes.py delete mode 100644 tests/bench/bytebuf-3-bytarray_map.py delete mode 100644 tests/bench/from_iter-1-list_bound.py delete mode 100644 tests/bench/from_iter-2-list_unbound.py delete mode 100644 tests/bench/from_iter-3-tuple_bound.py delete mode 100644 tests/bench/from_iter-4-tuple_unbound.py delete mode 100644 tests/bench/from_iter-5-bytes_bound.py delete mode 100644 tests/bench/from_iter-6-bytes_unbound.py delete mode 100644 tests/bench/from_iter-7-bytearray_bound.py delete mode 100644 tests/bench/from_iter-8-bytearray_unbound.py delete mode 100644 tests/bench/func_args-1.1-pos_1.py delete mode 100644 tests/bench/func_args-1.2-pos_3.py delete mode 100644 tests/bench/func_args-2-pos_default_2_of_3.py delete mode 100644 tests/bench/func_args-3.1-kw_1.py delete mode 100644 tests/bench/func_args-3.2-kw_3.py delete mode 100644 tests/bench/func_builtin-1-enum_pos.py delete mode 100644 tests/bench/func_builtin-2-enum_kw.py delete mode 100644 tests/bench/funcall-1-inline.py delete mode 100644 tests/bench/funcall-2-funcall.py delete mode 100644 tests/bench/funcall-3-funcall-local.py delete mode 100644 tests/bench/loop_count-1-range.py delete mode 100644 tests/bench/loop_count-2-range_iter.py delete mode 100644 tests/bench/loop_count-3-while_up.py delete mode 100644 tests/bench/loop_count-4-while_down_gt.py delete mode 100644 tests/bench/loop_count-5-while_down_ne.py delete mode 100644 tests/bench/loop_count-5.1-while_down_ne_localvar.py delete mode 100644 tests/bench/var-1-constant.py delete mode 100644 tests/bench/var-2-global.py delete mode 100644 tests/bench/var-3-local.py delete mode 100644 tests/bench/var-4-arg.py delete mode 100644 tests/bench/var-5-class-attr.py delete mode 100644 tests/bench/var-6-instance-attr.py delete mode 100644 tests/bench/var-6.1-instance-attr-5.py delete mode 100644 tests/bench/var-7-instance-meth.py delete mode 100644 tests/bench/var-8-namedtuple-1st.py delete mode 100644 tests/bench/var-8.1-namedtuple-5th.py create mode 100644 tests/internal_bench/arrayop-1-list_inplace.py create mode 100644 tests/internal_bench/arrayop-2-list_map.py create mode 100644 tests/internal_bench/arrayop-3-bytearray_inplace.py create mode 100644 tests/internal_bench/arrayop-4-bytearray_map.py create mode 100644 tests/internal_bench/bench.py create mode 100644 tests/internal_bench/bytealloc-1-bytes_n.py create mode 100644 tests/internal_bench/bytealloc-2-repeat.py create mode 100644 tests/internal_bench/bytebuf-1-inplace.py create mode 100644 tests/internal_bench/bytebuf-2-join_map_bytes.py create mode 100644 tests/internal_bench/bytebuf-3-bytarray_map.py create mode 100644 tests/internal_bench/from_iter-1-list_bound.py create mode 100644 tests/internal_bench/from_iter-2-list_unbound.py create mode 100644 tests/internal_bench/from_iter-3-tuple_bound.py create mode 100644 tests/internal_bench/from_iter-4-tuple_unbound.py create mode 100644 tests/internal_bench/from_iter-5-bytes_bound.py create mode 100644 tests/internal_bench/from_iter-6-bytes_unbound.py create mode 100644 tests/internal_bench/from_iter-7-bytearray_bound.py create mode 100644 tests/internal_bench/from_iter-8-bytearray_unbound.py create mode 100644 tests/internal_bench/func_args-1.1-pos_1.py create mode 100644 tests/internal_bench/func_args-1.2-pos_3.py create mode 100644 tests/internal_bench/func_args-2-pos_default_2_of_3.py create mode 100644 tests/internal_bench/func_args-3.1-kw_1.py create mode 100644 tests/internal_bench/func_args-3.2-kw_3.py create mode 100644 tests/internal_bench/func_builtin-1-enum_pos.py create mode 100644 tests/internal_bench/func_builtin-2-enum_kw.py create mode 100644 tests/internal_bench/funcall-1-inline.py create mode 100644 tests/internal_bench/funcall-2-funcall.py create mode 100644 tests/internal_bench/funcall-3-funcall-local.py create mode 100644 tests/internal_bench/loop_count-1-range.py create mode 100644 tests/internal_bench/loop_count-2-range_iter.py create mode 100644 tests/internal_bench/loop_count-3-while_up.py create mode 100644 tests/internal_bench/loop_count-4-while_down_gt.py create mode 100644 tests/internal_bench/loop_count-5-while_down_ne.py create mode 100644 tests/internal_bench/loop_count-5.1-while_down_ne_localvar.py create mode 100644 tests/internal_bench/var-1-constant.py create mode 100644 tests/internal_bench/var-2-global.py create mode 100644 tests/internal_bench/var-3-local.py create mode 100644 tests/internal_bench/var-4-arg.py create mode 100644 tests/internal_bench/var-5-class-attr.py create mode 100644 tests/internal_bench/var-6-instance-attr.py create mode 100644 tests/internal_bench/var-6.1-instance-attr-5.py create mode 100644 tests/internal_bench/var-7-instance-meth.py create mode 100644 tests/internal_bench/var-8-namedtuple-1st.py create mode 100644 tests/internal_bench/var-8.1-namedtuple-5th.py delete mode 100755 tests/run-bench-tests create mode 100755 tests/run-internalbench.py (limited to 'tests') diff --git a/tests/bench/arrayop-1-list_inplace.py b/tests/bench/arrayop-1-list_inplace.py deleted file mode 100644 index 0ee1ef2ec..000000000 --- a/tests/bench/arrayop-1-list_inplace.py +++ /dev/null @@ -1,12 +0,0 @@ -# Array operation -# Type: list, inplace operation using for. What's good about this -# method is that it doesn't require any extra memory allocation. -import bench - -def test(num): - for i in iter(range(num//10000)): - arr = [0] * 1000 - for i in range(len(arr)): - arr[i] += 1 - -bench.run(test) diff --git a/tests/bench/arrayop-2-list_map.py b/tests/bench/arrayop-2-list_map.py deleted file mode 100644 index 9d5095c53..000000000 --- a/tests/bench/arrayop-2-list_map.py +++ /dev/null @@ -1,12 +0,0 @@ -# Array operation -# Type: list, map() call. This method requires allocation of -# the same amount of memory as original array (to hold result -# array). On the other hand, input array stays intact. -import bench - -def test(num): - for i in iter(range(num//10000)): - arr = [0] * 1000 - arr2 = list(map(lambda x: x + 1, arr)) - -bench.run(test) diff --git a/tests/bench/arrayop-3-bytearray_inplace.py b/tests/bench/arrayop-3-bytearray_inplace.py deleted file mode 100644 index a6d628070..000000000 --- a/tests/bench/arrayop-3-bytearray_inplace.py +++ /dev/null @@ -1,12 +0,0 @@ -# Array operation -# Type: bytearray, inplace operation using for. What's good about this -# method is that it doesn't require any extra memory allocation. -import bench - -def test(num): - for i in iter(range(num//10000)): - arr = bytearray(b"\0" * 1000) - for i in range(len(arr)): - arr[i] += 1 - -bench.run(test) diff --git a/tests/bench/arrayop-4-bytearray_map.py b/tests/bench/arrayop-4-bytearray_map.py deleted file mode 100644 index 1b92a4096..000000000 --- a/tests/bench/arrayop-4-bytearray_map.py +++ /dev/null @@ -1,12 +0,0 @@ -# Array operation -# Type: list, map() call. This method requires allocation of -# the same amount of memory as original array (to hold result -# array). On the other hand, input array stays intact. -import bench - -def test(num): - for i in iter(range(num//10000)): - arr = bytearray(b"\0" * 1000) - arr2 = bytearray(map(lambda x: x + 1, arr)) - -bench.run(test) diff --git a/tests/bench/bench.py b/tests/bench/bench.py deleted file mode 100644 index 0cd40a93f..000000000 --- a/tests/bench/bench.py +++ /dev/null @@ -1,10 +0,0 @@ -import time - - -ITERS = 20000000 - -def run(f): - t = time.time() - f(ITERS) - t = time.time() - t - print(t) diff --git a/tests/bench/bytealloc-1-bytes_n.py b/tests/bench/bytealloc-1-bytes_n.py deleted file mode 100644 index 4a4bbc6fa..000000000 --- a/tests/bench/bytealloc-1-bytes_n.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in iter(range(num // 1000)): - bytes(10000) - -bench.run(test) diff --git a/tests/bench/bytealloc-2-repeat.py b/tests/bench/bytealloc-2-repeat.py deleted file mode 100644 index 786a80462..000000000 --- a/tests/bench/bytealloc-2-repeat.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in iter(range(num // 1000)): - b"\0" * 10000 - -bench.run(test) diff --git a/tests/bench/bytebuf-1-inplace.py b/tests/bench/bytebuf-1-inplace.py deleted file mode 100644 index 7e7d9391c..000000000 --- a/tests/bench/bytebuf-1-inplace.py +++ /dev/null @@ -1,11 +0,0 @@ -# Doing some operation on bytearray -# Inplace - the most memory efficient way -import bench - -def test(num): - for i in iter(range(num//10000)): - ba = bytearray(b"\0" * 1000) - for i in range(len(ba)): - ba[i] += 1 - -bench.run(test) diff --git a/tests/bench/bytebuf-2-join_map_bytes.py b/tests/bench/bytebuf-2-join_map_bytes.py deleted file mode 100644 index daa622991..000000000 --- a/tests/bench/bytebuf-2-join_map_bytes.py +++ /dev/null @@ -1,12 +0,0 @@ -# Doing some operation on bytearray -# Pretty weird way - map bytearray thru function, but make sure that -# function return bytes of size 1, then join them together. Surely, -# this is slowest way to do it. -import bench - -def test(num): - for i in iter(range(num//10000)): - ba = bytearray(b"\0" * 1000) - ba2 = b''.join(map(lambda x:bytes([x + 1]), ba)) - -bench.run(test) diff --git a/tests/bench/bytebuf-3-bytarray_map.py b/tests/bench/bytebuf-3-bytarray_map.py deleted file mode 100644 index 078d08e99..000000000 --- a/tests/bench/bytebuf-3-bytarray_map.py +++ /dev/null @@ -1,10 +0,0 @@ -# Doing some operation on bytearray -# No joins, but still map(). -import bench - -def test(num): - for i in iter(range(num//10000)): - ba = bytearray(b"\0" * 1000) - ba2 = bytearray(map(lambda x: x + 1, ba)) - -bench.run(test) diff --git a/tests/bench/from_iter-1-list_bound.py b/tests/bench/from_iter-1-list_bound.py deleted file mode 100644 index d209daecc..000000000 --- a/tests/bench/from_iter-1-list_bound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index be019c52f..000000000 --- a/tests/bench/from_iter-2-list_unbound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7b7fa36c6..000000000 --- a/tests/bench/from_iter-3-tuple_bound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7c7f134c8..000000000 --- a/tests/bench/from_iter-4-tuple_unbound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index b793a3207..000000000 --- a/tests/bench/from_iter-5-bytes_bound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 20aa55627..000000000 --- a/tests/bench/from_iter-6-bytes_unbound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 72001a05c..000000000 --- a/tests/bench/from_iter-7-bytearray_bound.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index e2263b8ef..000000000 --- a/tests/bench/from_iter-8-bytearray_unbound.py +++ /dev/null @@ -1,8 +0,0 @@ -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) diff --git a/tests/bench/func_args-1.1-pos_1.py b/tests/bench/func_args-1.1-pos_1.py deleted file mode 100644 index eee0ea828..000000000 --- a/tests/bench/func_args-1.1-pos_1.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -def func(a): - pass - -def test(num): - for i in iter(range(num)): - func(i) - -bench.run(test) diff --git a/tests/bench/func_args-1.2-pos_3.py b/tests/bench/func_args-1.2-pos_3.py deleted file mode 100644 index 7e03ee2f8..000000000 --- a/tests/bench/func_args-1.2-pos_3.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -def func(a, b, c): - pass - -def test(num): - for i in iter(range(num)): - func(i, i, i) - -bench.run(test) diff --git a/tests/bench/func_args-2-pos_default_2_of_3.py b/tests/bench/func_args-2-pos_default_2_of_3.py deleted file mode 100644 index 1fa0fbda5..000000000 --- a/tests/bench/func_args-2-pos_default_2_of_3.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -def func(a, b=1, c=2): - pass - -def test(num): - for i in iter(range(num)): - func(i) - -bench.run(test) diff --git a/tests/bench/func_args-3.1-kw_1.py b/tests/bench/func_args-3.1-kw_1.py deleted file mode 100644 index 7bc81e5be..000000000 --- a/tests/bench/func_args-3.1-kw_1.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -def func(a): - pass - -def test(num): - for i in iter(range(num)): - func(a=i) - -bench.run(test) diff --git a/tests/bench/func_args-3.2-kw_3.py b/tests/bench/func_args-3.2-kw_3.py deleted file mode 100644 index 7f9510684..000000000 --- a/tests/bench/func_args-3.2-kw_3.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -def func(a, b, c): - pass - -def test(num): - for i in iter(range(num)): - func(c=i, b=i, a=i) - -bench.run(test) diff --git a/tests/bench/func_builtin-1-enum_pos.py b/tests/bench/func_builtin-1-enum_pos.py deleted file mode 100644 index 20935164e..000000000 --- a/tests/bench/func_builtin-1-enum_pos.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in iter(range(num//20)): - enumerate([1, 2], 1) - -bench.run(test) diff --git a/tests/bench/func_builtin-2-enum_kw.py b/tests/bench/func_builtin-2-enum_kw.py deleted file mode 100644 index 6c5e44419..000000000 --- a/tests/bench/func_builtin-2-enum_kw.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in iter(range(num//20)): - enumerate(iterable=[1, 2], start=1) - -bench.run(test) diff --git a/tests/bench/funcall-1-inline.py b/tests/bench/funcall-1-inline.py deleted file mode 100644 index fbeb79630..000000000 --- a/tests/bench/funcall-1-inline.py +++ /dev/null @@ -1,9 +0,0 @@ -# Function call overhead test -# Establish a baseline for performing a trivial operation inline -import bench - -def test(num): - for i in iter(range(num)): - a = i + 1 - -bench.run(test) diff --git a/tests/bench/funcall-2-funcall.py b/tests/bench/funcall-2-funcall.py deleted file mode 100644 index d5c36c60a..000000000 --- a/tests/bench/funcall-2-funcall.py +++ /dev/null @@ -1,12 +0,0 @@ -# Function call overhead test -# Perform the same trivial operation as global function call -import bench - -def f(x): - return x + 1 - -def test(num): - for i in iter(range(num)): - a = f(i) - -bench.run(test) diff --git a/tests/bench/funcall-3-funcall-local.py b/tests/bench/funcall-3-funcall-local.py deleted file mode 100644 index 1a6d728c6..000000000 --- a/tests/bench/funcall-3-funcall-local.py +++ /dev/null @@ -1,16 +0,0 @@ -# Function call overhead test -# Perform the same trivial operation as calling function, cached in a -# local variable. This is commonly known optimization for overly dynamic -# languages (the idea is to cut on symbolic look up overhead, as local -# variables are accessed by offset, not by name) -import bench - -def f(x): - return x + 1 - -def test(num): - f_ = f - for i in iter(range(num)): - a = f_(i) - -bench.run(test) diff --git a/tests/bench/loop_count-1-range.py b/tests/bench/loop_count-1-range.py deleted file mode 100644 index e22adf6cb..000000000 --- a/tests/bench/loop_count-1-range.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in range(num): - pass - -bench.run(test) diff --git a/tests/bench/loop_count-2-range_iter.py b/tests/bench/loop_count-2-range_iter.py deleted file mode 100644 index fe4a3857e..000000000 --- a/tests/bench/loop_count-2-range_iter.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - for i in iter(range(num)): - pass - -bench.run(test) diff --git a/tests/bench/loop_count-3-while_up.py b/tests/bench/loop_count-3-while_up.py deleted file mode 100644 index 1ab8054a0..000000000 --- a/tests/bench/loop_count-3-while_up.py +++ /dev/null @@ -1,8 +0,0 @@ -import bench - -def test(num): - i = 0 - while i < num: - i += 1 - -bench.run(test) diff --git a/tests/bench/loop_count-4-while_down_gt.py b/tests/bench/loop_count-4-while_down_gt.py deleted file mode 100644 index de8dee2ca..000000000 --- a/tests/bench/loop_count-4-while_down_gt.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - while num > 0: - num -= 1 - -bench.run(test) diff --git a/tests/bench/loop_count-5-while_down_ne.py b/tests/bench/loop_count-5-while_down_ne.py deleted file mode 100644 index b9a1af414..000000000 --- a/tests/bench/loop_count-5-while_down_ne.py +++ /dev/null @@ -1,7 +0,0 @@ -import bench - -def test(num): - while num != 0: - num -= 1 - -bench.run(test) diff --git a/tests/bench/loop_count-5.1-while_down_ne_localvar.py b/tests/bench/loop_count-5.1-while_down_ne_localvar.py deleted file mode 100644 index 96bdb9129..000000000 --- a/tests/bench/loop_count-5.1-while_down_ne_localvar.py +++ /dev/null @@ -1,8 +0,0 @@ -import bench - -def test(num): - zero = 0 - while num != zero: - num -= 1 - -bench.run(test) diff --git a/tests/bench/var-1-constant.py b/tests/bench/var-1-constant.py deleted file mode 100644 index eec977909..000000000 --- a/tests/bench/var-1-constant.py +++ /dev/null @@ -1,8 +0,0 @@ -import bench - -def test(num): - i = 0 - while i < 20000000: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-2-global.py b/tests/bench/var-2-global.py deleted file mode 100644 index 5758ad61a..000000000 --- a/tests/bench/var-2-global.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - -ITERS = 20000000 - -def test(num): - i = 0 - while i < ITERS: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-3-local.py b/tests/bench/var-3-local.py deleted file mode 100644 index 124b48429..000000000 --- a/tests/bench/var-3-local.py +++ /dev/null @@ -1,10 +0,0 @@ -import bench - - -def test(num): - ITERS = 20000000 - i = 0 - while i < ITERS: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-4-arg.py b/tests/bench/var-4-arg.py deleted file mode 100644 index cf050c58f..000000000 --- a/tests/bench/var-4-arg.py +++ /dev/null @@ -1,9 +0,0 @@ -import bench - - -def test(num): - i = 0 - while i < num: - i += 1 - -bench.run(lambda n:test(20000000)) diff --git a/tests/bench/var-5-class-attr.py b/tests/bench/var-5-class-attr.py deleted file mode 100644 index 02ae874ac..000000000 --- a/tests/bench/var-5-class-attr.py +++ /dev/null @@ -1,11 +0,0 @@ -import bench - -class Foo: - num = 20000000 - -def test(num): - i = 0 - while i < Foo.num: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-6-instance-attr.py b/tests/bench/var-6-instance-attr.py deleted file mode 100644 index 787ed870f..000000000 --- a/tests/bench/var-6-instance-attr.py +++ /dev/null @@ -1,14 +0,0 @@ -import bench - -class Foo: - - def __init__(self): - self.num = 20000000 - -def test(num): - o = Foo() - i = 0 - while i < o.num: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-6.1-instance-attr-5.py b/tests/bench/var-6.1-instance-attr-5.py deleted file mode 100644 index e8d338360..000000000 --- a/tests/bench/var-6.1-instance-attr-5.py +++ /dev/null @@ -1,18 +0,0 @@ -import bench - -class Foo: - - def __init__(self): - self.num1 = 0 - self.num2 = 0 - self.num3 = 0 - self.num4 = 0 - self.num = 20000000 - -def test(num): - o = Foo() - i = 0 - while i < o.num: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-7-instance-meth.py b/tests/bench/var-7-instance-meth.py deleted file mode 100644 index f9d463f40..000000000 --- a/tests/bench/var-7-instance-meth.py +++ /dev/null @@ -1,17 +0,0 @@ -import bench - -class Foo: - - def __init__(self): - self._num = 20000000 - - def num(self): - return self._num - -def test(num): - o = Foo() - i = 0 - while i < o.num(): - i += 1 - -bench.run(test) diff --git a/tests/bench/var-8-namedtuple-1st.py b/tests/bench/var-8-namedtuple-1st.py deleted file mode 100644 index d862480a5..000000000 --- a/tests/bench/var-8-namedtuple-1st.py +++ /dev/null @@ -1,12 +0,0 @@ -import bench -from ucollections import namedtuple - -T = namedtuple("Tup", ["num", "bar"]) - -def test(num): - t = T(20000000, 0) - i = 0 - while i < t.num: - i += 1 - -bench.run(test) diff --git a/tests/bench/var-8.1-namedtuple-5th.py b/tests/bench/var-8.1-namedtuple-5th.py deleted file mode 100644 index 0bcf66180..000000000 --- a/tests/bench/var-8.1-namedtuple-5th.py +++ /dev/null @@ -1,12 +0,0 @@ -import bench -from ucollections import namedtuple - -T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"]) - -def test(num): - t = T(0, 0, 0, 0, 20000000) - i = 0 - while i < t.num: - i += 1 - -bench.run(test) diff --git a/tests/internal_bench/arrayop-1-list_inplace.py b/tests/internal_bench/arrayop-1-list_inplace.py new file mode 100644 index 000000000..0ee1ef2ec --- /dev/null +++ b/tests/internal_bench/arrayop-1-list_inplace.py @@ -0,0 +1,12 @@ +# Array operation +# Type: list, inplace operation using for. What's good about this +# method is that it doesn't require any extra memory allocation. +import bench + +def test(num): + for i in iter(range(num//10000)): + arr = [0] * 1000 + for i in range(len(arr)): + arr[i] += 1 + +bench.run(test) diff --git a/tests/internal_bench/arrayop-2-list_map.py b/tests/internal_bench/arrayop-2-list_map.py new file mode 100644 index 000000000..9d5095c53 --- /dev/null +++ b/tests/internal_bench/arrayop-2-list_map.py @@ -0,0 +1,12 @@ +# Array operation +# Type: list, map() call. This method requires allocation of +# the same amount of memory as original array (to hold result +# array). On the other hand, input array stays intact. +import bench + +def test(num): + for i in iter(range(num//10000)): + arr = [0] * 1000 + arr2 = list(map(lambda x: x + 1, arr)) + +bench.run(test) diff --git a/tests/internal_bench/arrayop-3-bytearray_inplace.py b/tests/internal_bench/arrayop-3-bytearray_inplace.py new file mode 100644 index 000000000..a6d628070 --- /dev/null +++ b/tests/internal_bench/arrayop-3-bytearray_inplace.py @@ -0,0 +1,12 @@ +# Array operation +# Type: bytearray, inplace operation using for. What's good about this +# method is that it doesn't require any extra memory allocation. +import bench + +def test(num): + for i in iter(range(num//10000)): + arr = bytearray(b"\0" * 1000) + for i in range(len(arr)): + arr[i] += 1 + +bench.run(test) diff --git a/tests/internal_bench/arrayop-4-bytearray_map.py b/tests/internal_bench/arrayop-4-bytearray_map.py new file mode 100644 index 000000000..1b92a4096 --- /dev/null +++ b/tests/internal_bench/arrayop-4-bytearray_map.py @@ -0,0 +1,12 @@ +# Array operation +# Type: list, map() call. This method requires allocation of +# the same amount of memory as original array (to hold result +# array). On the other hand, input array stays intact. +import bench + +def test(num): + for i in iter(range(num//10000)): + arr = bytearray(b"\0" * 1000) + arr2 = bytearray(map(lambda x: x + 1, arr)) + +bench.run(test) diff --git a/tests/internal_bench/bench.py b/tests/internal_bench/bench.py new file mode 100644 index 000000000..0cd40a93f --- /dev/null +++ b/tests/internal_bench/bench.py @@ -0,0 +1,10 @@ +import time + + +ITERS = 20000000 + +def run(f): + t = time.time() + f(ITERS) + t = time.time() - t + print(t) diff --git a/tests/internal_bench/bytealloc-1-bytes_n.py b/tests/internal_bench/bytealloc-1-bytes_n.py new file mode 100644 index 000000000..4a4bbc6fa --- /dev/null +++ b/tests/internal_bench/bytealloc-1-bytes_n.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in iter(range(num // 1000)): + bytes(10000) + +bench.run(test) diff --git a/tests/internal_bench/bytealloc-2-repeat.py b/tests/internal_bench/bytealloc-2-repeat.py new file mode 100644 index 000000000..786a80462 --- /dev/null +++ b/tests/internal_bench/bytealloc-2-repeat.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in iter(range(num // 1000)): + b"\0" * 10000 + +bench.run(test) diff --git a/tests/internal_bench/bytebuf-1-inplace.py b/tests/internal_bench/bytebuf-1-inplace.py new file mode 100644 index 000000000..7e7d9391c --- /dev/null +++ b/tests/internal_bench/bytebuf-1-inplace.py @@ -0,0 +1,11 @@ +# Doing some operation on bytearray +# Inplace - the most memory efficient way +import bench + +def test(num): + for i in iter(range(num//10000)): + ba = bytearray(b"\0" * 1000) + for i in range(len(ba)): + ba[i] += 1 + +bench.run(test) diff --git a/tests/internal_bench/bytebuf-2-join_map_bytes.py b/tests/internal_bench/bytebuf-2-join_map_bytes.py new file mode 100644 index 000000000..daa622991 --- /dev/null +++ b/tests/internal_bench/bytebuf-2-join_map_bytes.py @@ -0,0 +1,12 @@ +# Doing some operation on bytearray +# Pretty weird way - map bytearray thru function, but make sure that +# function return bytes of size 1, then join them together. Surely, +# this is slowest way to do it. +import bench + +def test(num): + for i in iter(range(num//10000)): + ba = bytearray(b"\0" * 1000) + ba2 = b''.join(map(lambda x:bytes([x + 1]), ba)) + +bench.run(test) diff --git a/tests/internal_bench/bytebuf-3-bytarray_map.py b/tests/internal_bench/bytebuf-3-bytarray_map.py new file mode 100644 index 000000000..078d08e99 --- /dev/null +++ b/tests/internal_bench/bytebuf-3-bytarray_map.py @@ -0,0 +1,10 @@ +# Doing some operation on bytearray +# No joins, but still map(). +import bench + +def test(num): + for i in iter(range(num//10000)): + ba = bytearray(b"\0" * 1000) + ba2 = bytearray(map(lambda x: x + 1, ba)) + +bench.run(test) diff --git a/tests/internal_bench/from_iter-1-list_bound.py b/tests/internal_bench/from_iter-1-list_bound.py new file mode 100644 index 000000000..d209daecc --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-2-list_unbound.py b/tests/internal_bench/from_iter-2-list_unbound.py new file mode 100644 index 000000000..be019c52f --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-3-tuple_bound.py b/tests/internal_bench/from_iter-3-tuple_bound.py new file mode 100644 index 000000000..7b7fa36c6 --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-4-tuple_unbound.py b/tests/internal_bench/from_iter-4-tuple_unbound.py new file mode 100644 index 000000000..7c7f134c8 --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-5-bytes_bound.py b/tests/internal_bench/from_iter-5-bytes_bound.py new file mode 100644 index 000000000..b793a3207 --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-6-bytes_unbound.py b/tests/internal_bench/from_iter-6-bytes_unbound.py new file mode 100644 index 000000000..20aa55627 --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-7-bytearray_bound.py b/tests/internal_bench/from_iter-7-bytearray_bound.py new file mode 100644 index 000000000..72001a05c --- /dev/null +++ b/tests/internal_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/internal_bench/from_iter-8-bytearray_unbound.py b/tests/internal_bench/from_iter-8-bytearray_unbound.py new file mode 100644 index 000000000..e2263b8ef --- /dev/null +++ b/tests/internal_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) diff --git a/tests/internal_bench/func_args-1.1-pos_1.py b/tests/internal_bench/func_args-1.1-pos_1.py new file mode 100644 index 000000000..eee0ea828 --- /dev/null +++ b/tests/internal_bench/func_args-1.1-pos_1.py @@ -0,0 +1,10 @@ +import bench + +def func(a): + pass + +def test(num): + for i in iter(range(num)): + func(i) + +bench.run(test) diff --git a/tests/internal_bench/func_args-1.2-pos_3.py b/tests/internal_bench/func_args-1.2-pos_3.py new file mode 100644 index 000000000..7e03ee2f8 --- /dev/null +++ b/tests/internal_bench/func_args-1.2-pos_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b, c): + pass + +def test(num): + for i in iter(range(num)): + func(i, i, i) + +bench.run(test) diff --git a/tests/internal_bench/func_args-2-pos_default_2_of_3.py b/tests/internal_bench/func_args-2-pos_default_2_of_3.py new file mode 100644 index 000000000..1fa0fbda5 --- /dev/null +++ b/tests/internal_bench/func_args-2-pos_default_2_of_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b=1, c=2): + pass + +def test(num): + for i in iter(range(num)): + func(i) + +bench.run(test) diff --git a/tests/internal_bench/func_args-3.1-kw_1.py b/tests/internal_bench/func_args-3.1-kw_1.py new file mode 100644 index 000000000..7bc81e5be --- /dev/null +++ b/tests/internal_bench/func_args-3.1-kw_1.py @@ -0,0 +1,10 @@ +import bench + +def func(a): + pass + +def test(num): + for i in iter(range(num)): + func(a=i) + +bench.run(test) diff --git a/tests/internal_bench/func_args-3.2-kw_3.py b/tests/internal_bench/func_args-3.2-kw_3.py new file mode 100644 index 000000000..7f9510684 --- /dev/null +++ b/tests/internal_bench/func_args-3.2-kw_3.py @@ -0,0 +1,10 @@ +import bench + +def func(a, b, c): + pass + +def test(num): + for i in iter(range(num)): + func(c=i, b=i, a=i) + +bench.run(test) diff --git a/tests/internal_bench/func_builtin-1-enum_pos.py b/tests/internal_bench/func_builtin-1-enum_pos.py new file mode 100644 index 000000000..20935164e --- /dev/null +++ b/tests/internal_bench/func_builtin-1-enum_pos.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in iter(range(num//20)): + enumerate([1, 2], 1) + +bench.run(test) diff --git a/tests/internal_bench/func_builtin-2-enum_kw.py b/tests/internal_bench/func_builtin-2-enum_kw.py new file mode 100644 index 000000000..6c5e44419 --- /dev/null +++ b/tests/internal_bench/func_builtin-2-enum_kw.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in iter(range(num//20)): + enumerate(iterable=[1, 2], start=1) + +bench.run(test) diff --git a/tests/internal_bench/funcall-1-inline.py b/tests/internal_bench/funcall-1-inline.py new file mode 100644 index 000000000..fbeb79630 --- /dev/null +++ b/tests/internal_bench/funcall-1-inline.py @@ -0,0 +1,9 @@ +# Function call overhead test +# Establish a baseline for performing a trivial operation inline +import bench + +def test(num): + for i in iter(range(num)): + a = i + 1 + +bench.run(test) diff --git a/tests/internal_bench/funcall-2-funcall.py b/tests/internal_bench/funcall-2-funcall.py new file mode 100644 index 000000000..d5c36c60a --- /dev/null +++ b/tests/internal_bench/funcall-2-funcall.py @@ -0,0 +1,12 @@ +# Function call overhead test +# Perform the same trivial operation as global function call +import bench + +def f(x): + return x + 1 + +def test(num): + for i in iter(range(num)): + a = f(i) + +bench.run(test) diff --git a/tests/internal_bench/funcall-3-funcall-local.py b/tests/internal_bench/funcall-3-funcall-local.py new file mode 100644 index 000000000..1a6d728c6 --- /dev/null +++ b/tests/internal_bench/funcall-3-funcall-local.py @@ -0,0 +1,16 @@ +# Function call overhead test +# Perform the same trivial operation as calling function, cached in a +# local variable. This is commonly known optimization for overly dynamic +# languages (the idea is to cut on symbolic look up overhead, as local +# variables are accessed by offset, not by name) +import bench + +def f(x): + return x + 1 + +def test(num): + f_ = f + for i in iter(range(num)): + a = f_(i) + +bench.run(test) diff --git a/tests/internal_bench/loop_count-1-range.py b/tests/internal_bench/loop_count-1-range.py new file mode 100644 index 000000000..e22adf6cb --- /dev/null +++ b/tests/internal_bench/loop_count-1-range.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in range(num): + pass + +bench.run(test) diff --git a/tests/internal_bench/loop_count-2-range_iter.py b/tests/internal_bench/loop_count-2-range_iter.py new file mode 100644 index 000000000..fe4a3857e --- /dev/null +++ b/tests/internal_bench/loop_count-2-range_iter.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + for i in iter(range(num)): + pass + +bench.run(test) diff --git a/tests/internal_bench/loop_count-3-while_up.py b/tests/internal_bench/loop_count-3-while_up.py new file mode 100644 index 000000000..1ab8054a0 --- /dev/null +++ b/tests/internal_bench/loop_count-3-while_up.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + i = 0 + while i < num: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/loop_count-4-while_down_gt.py b/tests/internal_bench/loop_count-4-while_down_gt.py new file mode 100644 index 000000000..de8dee2ca --- /dev/null +++ b/tests/internal_bench/loop_count-4-while_down_gt.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + while num > 0: + num -= 1 + +bench.run(test) diff --git a/tests/internal_bench/loop_count-5-while_down_ne.py b/tests/internal_bench/loop_count-5-while_down_ne.py new file mode 100644 index 000000000..b9a1af414 --- /dev/null +++ b/tests/internal_bench/loop_count-5-while_down_ne.py @@ -0,0 +1,7 @@ +import bench + +def test(num): + while num != 0: + num -= 1 + +bench.run(test) diff --git a/tests/internal_bench/loop_count-5.1-while_down_ne_localvar.py b/tests/internal_bench/loop_count-5.1-while_down_ne_localvar.py new file mode 100644 index 000000000..96bdb9129 --- /dev/null +++ b/tests/internal_bench/loop_count-5.1-while_down_ne_localvar.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + zero = 0 + while num != zero: + num -= 1 + +bench.run(test) diff --git a/tests/internal_bench/var-1-constant.py b/tests/internal_bench/var-1-constant.py new file mode 100644 index 000000000..eec977909 --- /dev/null +++ b/tests/internal_bench/var-1-constant.py @@ -0,0 +1,8 @@ +import bench + +def test(num): + i = 0 + while i < 20000000: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-2-global.py b/tests/internal_bench/var-2-global.py new file mode 100644 index 000000000..5758ad61a --- /dev/null +++ b/tests/internal_bench/var-2-global.py @@ -0,0 +1,10 @@ +import bench + +ITERS = 20000000 + +def test(num): + i = 0 + while i < ITERS: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-3-local.py b/tests/internal_bench/var-3-local.py new file mode 100644 index 000000000..124b48429 --- /dev/null +++ b/tests/internal_bench/var-3-local.py @@ -0,0 +1,10 @@ +import bench + + +def test(num): + ITERS = 20000000 + i = 0 + while i < ITERS: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-4-arg.py b/tests/internal_bench/var-4-arg.py new file mode 100644 index 000000000..cf050c58f --- /dev/null +++ b/tests/internal_bench/var-4-arg.py @@ -0,0 +1,9 @@ +import bench + + +def test(num): + i = 0 + while i < num: + i += 1 + +bench.run(lambda n:test(20000000)) diff --git a/tests/internal_bench/var-5-class-attr.py b/tests/internal_bench/var-5-class-attr.py new file mode 100644 index 000000000..02ae874ac --- /dev/null +++ b/tests/internal_bench/var-5-class-attr.py @@ -0,0 +1,11 @@ +import bench + +class Foo: + num = 20000000 + +def test(num): + i = 0 + while i < Foo.num: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-6-instance-attr.py b/tests/internal_bench/var-6-instance-attr.py new file mode 100644 index 000000000..787ed870f --- /dev/null +++ b/tests/internal_bench/var-6-instance-attr.py @@ -0,0 +1,14 @@ +import bench + +class Foo: + + def __init__(self): + self.num = 20000000 + +def test(num): + o = Foo() + i = 0 + while i < o.num: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-6.1-instance-attr-5.py b/tests/internal_bench/var-6.1-instance-attr-5.py new file mode 100644 index 000000000..e8d338360 --- /dev/null +++ b/tests/internal_bench/var-6.1-instance-attr-5.py @@ -0,0 +1,18 @@ +import bench + +class Foo: + + def __init__(self): + self.num1 = 0 + self.num2 = 0 + self.num3 = 0 + self.num4 = 0 + self.num = 20000000 + +def test(num): + o = Foo() + i = 0 + while i < o.num: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-7-instance-meth.py b/tests/internal_bench/var-7-instance-meth.py new file mode 100644 index 000000000..f9d463f40 --- /dev/null +++ b/tests/internal_bench/var-7-instance-meth.py @@ -0,0 +1,17 @@ +import bench + +class Foo: + + def __init__(self): + self._num = 20000000 + + def num(self): + return self._num + +def test(num): + o = Foo() + i = 0 + while i < o.num(): + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-8-namedtuple-1st.py b/tests/internal_bench/var-8-namedtuple-1st.py new file mode 100644 index 000000000..d862480a5 --- /dev/null +++ b/tests/internal_bench/var-8-namedtuple-1st.py @@ -0,0 +1,12 @@ +import bench +from ucollections import namedtuple + +T = namedtuple("Tup", ["num", "bar"]) + +def test(num): + t = T(20000000, 0) + i = 0 + while i < t.num: + i += 1 + +bench.run(test) diff --git a/tests/internal_bench/var-8.1-namedtuple-5th.py b/tests/internal_bench/var-8.1-namedtuple-5th.py new file mode 100644 index 000000000..0bcf66180 --- /dev/null +++ b/tests/internal_bench/var-8.1-namedtuple-5th.py @@ -0,0 +1,12 @@ +import bench +from ucollections import namedtuple + +T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"]) + +def test(num): + t = T(0, 0, 0, 0, 20000000) + i = 0 + while i < t.num: + i += 1 + +bench.run(test) diff --git a/tests/run-bench-tests b/tests/run-bench-tests deleted file mode 100755 index f4a6776cb..000000000 --- a/tests/run-bench-tests +++ /dev/null @@ -1,97 +0,0 @@ -#! /usr/bin/env python3 - -import os -import subprocess -import sys -import argparse -import re -from glob import glob -from collections import defaultdict - -# Tests require at least CPython 3.3. If your default python3 executable -# is of lower version, you can point MICROPY_CPYTHON3 environment var -# to the correct executable. -if os.name == 'nt': - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') -else: - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') - -def run_tests(pyb, test_dict): - test_count = 0 - testcase_count = 0 - - for base_test, tests in sorted(test_dict.items()): - print(base_test + ":") - for test_file in tests: - - # run MicroPython - if pyb is None: - # run on PC - try: - output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=bytecode', test_file[0]]) - except subprocess.CalledProcessError: - output_mupy = b'CRASH' - else: - # run on pyboard - pyb.enter_raw_repl() - try: - output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') - except pyboard.PyboardError: - output_mupy = b'CRASH' - - output_mupy = float(output_mupy.strip()) - test_file[1] = output_mupy - testcase_count += 1 - - test_count += 1 - baseline = None - for t in tests: - if baseline is None: - baseline = t[1] - print(" %.3fs (%+06.2f%%) %s" % (t[1], (t[1] * 100 / baseline) - 100, t[0])) - - print("{} tests performed ({} individual testcases)".format(test_count, testcase_count)) - - # all tests succeeded - return True - -def main(): - cmd_parser = argparse.ArgumentParser(description='Run tests for MicroPython.') - cmd_parser.add_argument('--pyboard', action='store_true', help='run the tests on the pyboard') - cmd_parser.add_argument('files', nargs='*', help='input test files') - args = cmd_parser.parse_args() - - # Note pyboard support is copied over from run-tests, not testes, and likely needs revamping - if args.pyboard: - import pyboard - pyb = pyboard.Pyboard('/dev/ttyACM0') - pyb.enter_raw_repl() - else: - pyb = None - - if len(args.files) == 0: - if pyb is None: - # run PC tests - test_dirs = ('bench',) - else: - # run pyboard tests - test_dirs = ('basics', 'float', 'pyb') - tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) - else: - # tests explicitly given - tests = sorted(args.files) - - test_dict = defaultdict(lambda: []) - for t in tests: - m = re.match(r"(.+?)-(.+)\.py", t) - if not m: - continue - test_dict[m.group(1)].append([t, None]) - - if not run_tests(pyb, test_dict): - sys.exit(1) - -if __name__ == "__main__": - main() diff --git a/tests/run-internalbench.py b/tests/run-internalbench.py new file mode 100755 index 000000000..f6294572f --- /dev/null +++ b/tests/run-internalbench.py @@ -0,0 +1,97 @@ +#! /usr/bin/env python3 + +import os +import subprocess +import sys +import argparse +import re +from glob import glob +from collections import defaultdict + +# Tests require at least CPython 3.3. If your default python3 executable +# is of lower version, you can point MICROPY_CPYTHON3 environment var +# to the correct executable. +if os.name == 'nt': + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') +else: + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') + +def run_tests(pyb, test_dict): + test_count = 0 + testcase_count = 0 + + for base_test, tests in sorted(test_dict.items()): + print(base_test + ":") + for test_file in tests: + + # run MicroPython + if pyb is None: + # run on PC + try: + output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=bytecode', test_file[0]]) + except subprocess.CalledProcessError: + output_mupy = b'CRASH' + else: + # run on pyboard + pyb.enter_raw_repl() + try: + output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') + except pyboard.PyboardError: + output_mupy = b'CRASH' + + output_mupy = float(output_mupy.strip()) + test_file[1] = output_mupy + testcase_count += 1 + + test_count += 1 + baseline = None + for t in tests: + if baseline is None: + baseline = t[1] + print(" %.3fs (%+06.2f%%) %s" % (t[1], (t[1] * 100 / baseline) - 100, t[0])) + + print("{} tests performed ({} individual testcases)".format(test_count, testcase_count)) + + # all tests succeeded + return True + +def main(): + cmd_parser = argparse.ArgumentParser(description='Run tests for MicroPython.') + cmd_parser.add_argument('--pyboard', action='store_true', help='run the tests on the pyboard') + cmd_parser.add_argument('files', nargs='*', help='input test files') + args = cmd_parser.parse_args() + + # Note pyboard support is copied over from run-tests, not testes, and likely needs revamping + if args.pyboard: + import pyboard + pyb = pyboard.Pyboard('/dev/ttyACM0') + pyb.enter_raw_repl() + else: + pyb = None + + if len(args.files) == 0: + if pyb is None: + # run PC tests + test_dirs = ('internal_bench',) + else: + # run pyboard tests + test_dirs = ('basics', 'float', 'pyb') + tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) + else: + # tests explicitly given + tests = sorted(args.files) + + test_dict = defaultdict(lambda: []) + for t in tests: + m = re.match(r"(.+?)-(.+)\.py", t) + if not m: + continue + test_dict[m.group(1)].append([t, None]) + + if not run_tests(pyb, test_dict): + sys.exit(1) + +if __name__ == "__main__": + main() -- cgit v1.2.3