#100DaysOfCode in Python Transcripts
Chapter: Days 49-51: Measuring performance
Lecture: PyCharm's profiling

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, so all of this was really
0:01 useful and helpful and I think we did a lot
0:03 of good stuff with it, but this text view,
0:06 while it is technically helpful, you really can do better.
0:12 In this simple program, what I'm going to show you
0:14 doesn't come out really that great
0:16 because there's so much overhead,
0:18 like I said, a sort of programmed start-up and stuff.
0:20 But in a real complex application,
0:22 you would really be able to make great use
0:25 of what I'm going to show you.
0:26 So, we saw that we can come over here
0:30 and run the profiler externally like this.
0:33 And that works fine,
0:34 or we can even use the API internally.
0:36 Let me show you one other option.
0:39 Now for this to work, we need to go back,
0:42 we need to take a bit of a step back into this mode here
0:46 where we're running the profiler from the command line.
0:50 Just the whole program basically.
0:52 So let's drop in this program PyCharm bit.
0:54 Let's drop this enabling and disabling and printing
0:58 and we can still leave everything else the same.
1:02 But we're going to take away the profiler API internally.
1:05 And we're going to run this just like normal, and it runs.
1:08 There's no output that is anything special.
1:11 But once you have a run configuration--
1:13 now this is only for those of you
1:15 who care about PyCharm and have the Pro Edition.
1:17 If you're using something else like Visual Studio Code
1:19 or something, you're going to have to do
1:21 what we've already seen, alright?
1:22 There are ways to implement these tools
1:24 outside of PyCharm, but this is pretty nice.
1:27 Once we create this,
1:28 we can run it here but if you go over there,
1:30 it'll say profile that. We click it, wait a second.
1:34 First of all, if you look up at the top, way at the top,
1:38 it is running the cProfiler.
1:43 And this list here is the list that you already saw.
1:46 But we can click on, say 'time'
1:49 and see, here's main, here's the
1:52 research py stuff we're doing,
1:54 here's the Hot Days, all that kind of stuff.
1:57 Here's the init that we're calling.
1:59 Same thing, but you can quickly jump around.
2:02 You can even say, "Show this on the call graph."
2:04 Well, of course, you see it right there.
2:07 This is a visualization of that result.
2:09 Let me come down here and zoom in, this will become useful.
2:14 Notice, here's our program, it's calling main,
2:17 it's calling "Hot Days, Wet Days, Cold Days."
2:18 These are pretty quick. Now we're calling this "Init."
2:22 We're calling this one 99 times,
2:25 but we're only going through the parse row
2:27 365 times. Remember, that's one year's worth of data,
2:32 365 rows, so even though we call this 99 times,
2:35 we're not actually parsing it 99 times,
2:38 we're just doing that for one round through the file.
2:41 So here you can see where you're spending your time.
2:43 You can actually visually go through it.
2:45 Like I said, in a real app, this is actually more helpful
2:48 because the overall program start-up is not
2:51 so significantly shown in the graph.
2:54 It's where your app's doing most of its work.
2:56 This is so simple that it kind of
2:57 gets lost in the noise, but this graphical view
3:01 is really, really nice as well.