##// END OF EJS Templates
Include "worst timings" from the tuning to find number of runs
MechCoder -
Show More
@@ -1006,20 +1006,28 b' python-profiler package from non-free.""")'
1006 exec(code, self.shell.user_ns, ns)
1006 exec(code, self.shell.user_ns, ns)
1007 timer.inner = ns["inner"]
1007 timer.inner = ns["inner"]
1008
1008
1009 # This is used to check if there is a huge difference between the
1010 # best and worst timings.
1011 # Issue: https://github.com/ipython/ipython/issues/6471
1012 worst_tuning = 0
1009 if number == 0:
1013 if number == 0:
1010 # determine number so that 0.2 <= total time < 2.0
1014 # determine number so that 0.2 <= total time < 2.0
1011 number = 1
1015 number = 1
1012 for _ in range(1, 10):
1016 for _ in range(1, 10):
1013 if timer.timeit(number) >= 0.2:
1017 time_number = timer.timeit(number)
1018 worst_tuning = max(worst_tuning, time_number / number)
1019 if time_number >= 0.2:
1014 break
1020 break
1015 number *= 10
1021 number *= 10
1016 all_runs = timer.repeat(repeat, number)
1022 all_runs = timer.repeat(repeat, number)
1017 best = min(all_runs) / number
1023 best = min(all_runs) / number
1018 if not quiet :
1024 if not quiet :
1019 worst = max(all_runs) / number
1025 worst = max(all_runs) / number
1026 if worst_tuning:
1027 worst = max(worst, worst_tuning)
1020 if worst > 4 * best:
1028 if worst > 4 * best:
1021 warn("Worst time is %0.2f times that of the best. Timings may "
1029 warn("Worst time is %0.2f times that of the best. Timings may "
1022 "be biased." % (worst / best))
1030 "be biased." % (worst / best))
1023 print(u"%d loops, best of %d: %s per loop" % (number, repeat,
1031 print(u"%d loops, best of %d: %s per loop" % (number, repeat,
1024 _format_time(best, precision)))
1032 _format_time(best, precision)))
1025 if tc > tc_min:
1033 if tc > tc_min:
General Comments 0
You need to be logged in to leave comments. Login now