delete reverse_double_chunks.py
This commit is contained in:
parent
50a83f3c0e
commit
43f24efbcf
|
@ -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")
|
Loading…
Reference in New Issue