fork download
  1. from itertools import accumulate
  2. import timeit
  3.  
  4. def suffix_maximums(l):
  5. return list(accumulate(l[::-1], max))[::-1]
  6. def suffix_maximums_2(l):
  7. return list(reversed(list(accumulate(reversed(l), max))))
  8.  
  9. l = [5, 4, 6, 2, 3, 1]
  10.  
  11. print(timeit.timeit('suffix_maximums(l)', globals=globals()))
  12. print(timeit.timeit('suffix_maximums_2(l)', globals=globals()))
Success #stdin #stdout 3.01s 9664KB
stdin
Standard input is empty
stdout
1.3507004585117102
1.633841508999467