Skip to content

Commit 953d792

Browse files
committed
-
1 parent 2f3d177 commit 953d792

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

docs/topics/cute-profile.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,23 @@ And now we run it:
8080

8181
>>> print(get_perfects(20000))
8282

83-
We still get the same result, but now a profiling table gets printed:
83+
We still get the same result, but now a profiling table gets printed::
8484

85-
6000 function calls in 6.142 seconds
85+
60000 function calls in 7.997 seconds
86+
87+
Ordered by: cumulative time
88+
89+
ncalls tottime percall cumtime percall filename:lineno(function)
90+
1 0.000 0.000 7.997 7.997 <string>:1(<module>)
91+
1 0.020 0.020 7.997 7.997 <pyshell#1>:2(get_perfects)
92+
19999 0.058 0.000 7.977 0.000 <pyshell#0>:5(is_perfect)
93+
19999 7.898 0.000 7.898 0.000 <pyshell#0>:1(get_divisors)
94+
19999 0.021 0.000 0.021 0.000 {sum}
95+
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
96+
8697

87-
Ordered by: cumulative time
98+
This table shows how long each function took. If you want to understand *exactly* what each number says in this table, see :func:`cProfile.run`.
8899

89-
ncalls tottime percall cumtime percall filename:lineno(function)
90-
1 0.000 0.000 6.142 6.142 :1()
91-
1 0.025 0.025 6.142 6.142 perfect_numbers.py:9(get_perfects)
92-
1999 0.045 0.000 6.117 0.003 perfect_numbers.py:6(is_perfect)
93-
1999 6.060 0.003 6.060 0.003 perfect_numbers.py:3(get_divisors)
94-
1999 0.012 0.000 0.012 0.000 {sum}
95-
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
96-
</pre>
97-
This table shows how long each function took. If you want to understand *exactly* what each number says in this table, <a href="http://docs.python.org/library/profile.html#cProfile.run">there's an explanation here</a>.
98100
The <code>tottime</code> column says how much time was spent inside this function, across all calls, and without counting the time that was spent in sub-functions. See how the <code>get_divisors</code> function in our example has a very high <code>tottime</code> of 6.060. This means that <code>get_divisors</code> is what's causing our program to run slow, and if we'll want to optimize the program, we should try to come up with a smarter way of finding all of a number's divisors than going one-by-one over all numbers.
99101
<code>profile_ready</code> has a bunch of other options that I won't explore there. In brief:
100102
<ul><li>The <code>condition</code> argument is something like a "breakpoint condition" in an IDE: It can be a function, usually a lambda, that takes the decorated function and any arguments and returns whether or not to profile it this time.</li>

0 commit comments

Comments
 (0)