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