Python Memory Management and Tips Transcripts
Chapter: Memory and classes
Lecture: Testing crowd sizes
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So let's check how long this took to create this crowd and then how much memory was used to. So let's go over here and say "t0 = datetime.
0:09
datetime.now()", and then we're gonna do this and then check. So why not a little try finally, hey? bring that in there.
0:20
And then we're going to say the change in time is as you would expect.
0:28
And then I'll just do a little print statement that says we created a crowd in however much time, convert this to milliseconds,
0:34
so let's just see that. Here we go. It took 459 milliseconds to create our 100,000 size crowd. The other thing that we want to check,
0:44
though, is how big is the crowd? So we'll just print out a little statement here, the size of the crowd,
0:53
we've got to get our size utility, and just like before, we need to have this bit at the top, so in case you're not using PyCharm,
1:07
things will still work. So here we're going to say, "get the full size of our crowd". Remember,
1:18
this traverses the whole object graph and it's gonna print it out in megabytes. So the "create_a_crowd" knows how long it takes,
1:24
and then we're just going to say how big it is. Created a crowd in 400 milliseconds, and the size of the crowd is 32 megabytes.
1:34
Alright, not bad at all. This doesn't really mean a lot to me. Like, What am I gonna compare this against? Is 32 MB's good or bad? I mean,
1:42
it is 100,000 people with lots of information about them. That's cool. And 400 milliseconds, also not too bad.
1:49
So we're gonna use this as our baseline and we're gonna create two other versions of our person implementation that are gonna improve upon this
1:57
and actually make it better, both the crowd size created or the crowd created in is gonna go down, and the crowd size is also gonna go down.