pocketlang/test/benchmark/list_reverse/list_reverse.py
2021-05-31 05:31:41 +05:30

16 lines
349 B
Python

from time import process_time as clock
from math import floor
def reverse_list(list):
count = floor(len(list) / 2)
for i in range(count):
last_index = len(list) - i - 1
list[i], list[last_index] = list[last_index], list[i]
return list
start = clock()
N = 20000000
l = list(range(N))
reverse_list(l)
print('elapsed: ', clock() - start, 's')