pocketlang/tests/benchmarks/list/list.rb

15 lines
284 B
Ruby
Raw Normal View History

2021-05-24 06:17:52 +08:00
def reverse_list(list)
(list.length >> 1).times do |i|
last_index = list.length - i - 1
list[i], list[last_index] = list[last_index], list[i]
end
end
N = 20000000
list = (0...N).to_a
start = Time.now
reverse_list(list)
2021-05-24 06:17:52 +08:00
puts "elapsed: " + (Time.now - start).to_s + ' s'