Code: Alles auswählen
def start_test(count=5, repeat=3):
functions = [func for name, func in globals().items() if
name.startswith('with_')]
result = {}
timer = time.time
for func in functions:
import_ = 'from __main__ import {0}'.format(func.__name__)
func_ = '{0}()'.format(func.__name__)
results = timeit.repeat(stmt=func_, setup=import_, timer=timer,
repeat=repeat, number=count)
result[func.__name__] = min(results), max(results)
result = sorted(result.items(), key=lambda e: e[0])
print('{0} repetitions of {1} runs:'.format(repeat, count))
print('\t\tmin\t\tmax')
for func, times in result:
print('{func}:\t{times[0]:f}\t{times[1]:f}'.format(times=times,
func=func))
if __name__ == '__main__':
args = map(int, sys.argv[1:3])
start_test(*args)
Code: Alles auswählen
$ python ./measure_sum.py 10 5
5 repetitions of 10 runs:
min max
with_filter: 0.856682 0.864453
with_for: 0.387800 0.404242
with_ifelse: 0.282156 0.295538
with_lc: 0.529992 0.540703
with_map: 1.683503 1.728494
with_reduce: 0.761827 0.793188
with_sub: 0.369928 0.388947
Code: Alles auswählen
$ python3 ./measure_sum.py 10 5
5 repetitions of 10 runs:
min max
with_filter: 1.111608 1.166339
with_for: 0.493963 0.498310
with_ifelse: 0.407400 0.417205
with_lc: 0.630200 0.632272
with_map: 1.335373 1.345122
with_reduce: 0.807354 0.809970
with_sub: 0.453200 0.454332
Ich will einfach auch mal etwas entwickelt haben, das sowas wie einen "Start"-Button hat...Sirius3 hat geschrieben:Der Name start_test ist auch etwas irreführend. da der Test gestartet durchgeführt und beendet wird.
Wer weiß? Soll Leute geben, die damit Milliarden verdient haben...
mutetella