Show More
@@ -597,6 +597,11 b' python-profiler package from non-free.""")' | |||||
597 | runner = self.default_runner |
|
597 | runner = self.default_runner | |
598 | if runner is None: |
|
598 | if runner is None: | |
599 | runner = self.shell.safe_execfile |
|
599 | runner = self.shell.safe_execfile | |
|
600 | ||||
|
601 | def run(): | |||
|
602 | runner(filename, prog_ns, prog_ns, | |||
|
603 | exit_ignore=exit_ignore) | |||
|
604 | ||||
600 | if 't' in opts: |
|
605 | if 't' in opts: | |
601 | # timed execution |
|
606 | # timed execution | |
602 | try: |
|
607 | try: | |
@@ -606,37 +611,10 b' python-profiler package from non-free.""")' | |||||
606 | return |
|
611 | return | |
607 | except (KeyError): |
|
612 | except (KeyError): | |
608 | nruns = 1 |
|
613 | nruns = 1 | |
609 |
|
|
614 | self._run_with_timing(run, nruns) | |
610 | if nruns == 1: |
|
|||
611 | t0 = clock2() |
|
|||
612 | runner(filename, prog_ns, prog_ns, |
|
|||
613 | exit_ignore=exit_ignore) |
|
|||
614 | t1 = clock2() |
|
|||
615 | t_usr = t1[0] - t0[0] |
|
|||
616 | t_sys = t1[1] - t0[1] |
|
|||
617 | print "\nIPython CPU timings (estimated):" |
|
|||
618 | print " User : %10.2f s." % t_usr |
|
|||
619 | print " System : %10.2f s." % t_sys |
|
|||
620 | else: |
|
|||
621 | runs = range(nruns) |
|
|||
622 | t0 = clock2() |
|
|||
623 | for nr in runs: |
|
|||
624 | runner(filename, prog_ns, prog_ns, |
|
|||
625 | exit_ignore=exit_ignore) |
|
|||
626 | t1 = clock2() |
|
|||
627 | t_usr = t1[0] - t0[0] |
|
|||
628 | t_sys = t1[1] - t0[1] |
|
|||
629 | print "\nIPython CPU timings (estimated):" |
|
|||
630 | print "Total runs performed:", nruns |
|
|||
631 | print " Times : %10s %10s" % ('Total', 'Per run') |
|
|||
632 | print " User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns) |
|
|||
633 | print " System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns) |
|
|||
634 | twall1 = time.time() |
|
|||
635 | print "Wall time: %10.2f s." % (twall1 - twall0) |
|
|||
636 |
|
||||
637 | else: |
|
615 | else: | |
638 | # regular execution |
|
616 | # regular execution | |
639 | runner(filename, prog_ns, prog_ns, exit_ignore=exit_ignore) |
|
617 | run() | |
640 |
|
618 | |||
641 | if 'i' in opts: |
|
619 | if 'i' in opts: | |
642 | self.shell.user_ns['__name__'] = __name__save |
|
620 | self.shell.user_ns['__name__'] = __name__save | |
@@ -676,7 +654,35 b' python-profiler package from non-free.""")' | |||||
676 | del sys.modules[main_mod_name] |
|
654 | del sys.modules[main_mod_name] | |
677 |
|
655 | |||
678 | return stats |
|
656 | return stats | |
679 |
|
657 | |||
|
658 | @staticmethod | |||
|
659 | def _run_with_timing(run, nruns): | |||
|
660 | twall0 = time.time() | |||
|
661 | if nruns == 1: | |||
|
662 | t0 = clock2() | |||
|
663 | run() | |||
|
664 | t1 = clock2() | |||
|
665 | t_usr = t1[0] - t0[0] | |||
|
666 | t_sys = t1[1] - t0[1] | |||
|
667 | print "\nIPython CPU timings (estimated):" | |||
|
668 | print " User : %10.2f s." % t_usr | |||
|
669 | print " System : %10.2f s." % t_sys | |||
|
670 | else: | |||
|
671 | runs = range(nruns) | |||
|
672 | t0 = clock2() | |||
|
673 | for nr in runs: | |||
|
674 | run() | |||
|
675 | t1 = clock2() | |||
|
676 | t_usr = t1[0] - t0[0] | |||
|
677 | t_sys = t1[1] - t0[1] | |||
|
678 | print "\nIPython CPU timings (estimated):" | |||
|
679 | print "Total runs performed:", nruns | |||
|
680 | print " Times : %10s %10s" % ('Total', 'Per run') | |||
|
681 | print " User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns) | |||
|
682 | print " System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns) | |||
|
683 | twall1 = time.time() | |||
|
684 | print "Wall time: %10.2f s." % (twall1 - twall0) | |||
|
685 | ||||
680 | @skip_doctest |
|
686 | @skip_doctest | |
681 | @line_cell_magic |
|
687 | @line_cell_magic | |
682 | def timeit(self, line='', cell=None): |
|
688 | def timeit(self, line='', cell=None): |
General Comments 0
You need to be logged in to leave comments.
Login now