1
0
Fork 0

delete reverse_double_chunks.py

This commit is contained in:
Intel A80486DX2-66 2024-04-11 08:29:21 +03:00
parent 50a83f3c0e
commit 43f24efbcf
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
1 changed files with 0 additions and 47 deletions

View File

@ -1,47 +0,0 @@
#!/usr/bin/python3
from timeit import timeit
BENCHMARK_COUNT = 180
SUPERTESTS = 90
def double_chunk_reverse_method1(a):
[a[i + 1 - i] for i in range(0, len(a))]
def double_chunk_reverse_method2(a):
[[a[i][0] ^ 1, a[i][1] ^ 1] for i in range(0, len(a))]
timeit_macro = lambda func_name, number, a: timeit(
"%s(%s)" % (func_name, a), setup="from __main__ import %s" % func_name,
number=number
)
if __name__ == "__main__":
print("Testing performance of two methods of double reversing chunks "
"for linear-sorted arrays:")
time1_total = 0
time2_total = 0
a = str([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
for i in range(SUPERTESTS):
bench_now = BENCHMARK_COUNT * i
time1 = timeit_macro("double_chunk_reverse_method1", bench_now, a)
time2 = timeit_macro("double_chunk_reverse_method2", bench_now, a)
time1_total += time1
time2_total += time2
time1_avg = time1_total / SUPERTESTS
time2_avg = time2_total / SUPERTESTS
print(f"Method #1 (normal):\t{time1_avg} seconds")
print(f"Method #2 (using XOR):\t{time2_avg} seconds")
if time1 < time2:
print("Method #1 is faster")
elif time1 > time2:
print("Method #2 is faster")
else:
print("Methods have similar performance")