6. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
7. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total timeit: 83
8. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
9. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 l_items = items while i < len( l_items ): total += calculate( l_items[i] ) i += 1 return total
10. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
11. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 73
12. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
13. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate( len=len ): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
14. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
15. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 77.1
16. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
17. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): x = items[i] total += 3*x*x - 2*x + (1 / x) i += 1 return total
18. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
19. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
20. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 60.5
21. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) @promise.constant([“len”,“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
22. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
23. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals())
24. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals()) timeit: 83 56.5
25. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
26. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items)
27. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items) timeit: 83 59
28. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum(calculate(i) for i in items)
29. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum([calculate(i) for i in items]) timeit: 83 42.6