#100DaysOfCode in Python Transcripts
Chapter: Days 49-51: Measuring performance
Lecture: Demo: Focus on our code
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Now one takeaway from this here
0:02
is that we're actually spending a ton
0:04
of startup time and other things.
0:06
And depending on how your code is working,
0:09
if it's intended to be called over and over again,
0:12
this is very common if you use like a web app,
0:14
and you start it and every time somebody hits this page,
0:16
some stuff is going to happen over and over.
0:19
You might not want to measure
0:20
the start up time so much as steady state time.
0:24
So let's do one real quick thing
0:25
before we actually get fully to the CPython API.
0:29
Let's just run this a lot.
0:31
So, then here we have this main.
0:33
Let's just run main like 100 times, or 50 times,
0:36
or something like that.
0:37
And measure that.
0:39
That will get rid of some of the variation.
0:40
It'll definitely suppress
0:42
some of the module Python startup times.
0:44
So we'll just say this.
0:47
Let's do it 25 times.
0:50
Now we're here and we'll run the same thing.
0:53
Once again, but it'll take a little bit longer.
0:55
Still, not long, right?
0:58
But you can see, it's going over and over again
1:00
it's doing this little printout here.
1:02
So now if we look over here,
1:03
here's our main, spending a little bit of time there.
1:07
Doing our research initialization,
1:09
we're spending a decent amount of time in parse row.
1:13
Over here, these are cumulative times.
1:15
So, like, for example, we're spending 210 milliseconds in module load,
1:18
but now we're spending 180 milliseconds in main.
1:23
That may be totally fast enough, maybe not.
1:25
On the Talk Python Training website,
1:28
we try to get things down to 10 milliseconds, 20 milliseconds.
1:33
Some of the pages that are really complicated,
1:34
you know, there's a lot going on.
1:36
It's like 50 milliseconds.
1:37
But you certainly want to try to get that number down.
1:39
I think if this was a web app,
1:41
that number would be too high.
1:43
Of course it's not, but what we're going to do is
1:45
we're going to look at what we're doing here
1:47
and at first try to understand why this is happening
1:50
and how we can make it faster.