Python Memory Management and Tips Transcripts
Chapter: Memory and classes
Lecture: Testing crowd sizes
0:00 So let's check how long this took to create this crowd and then how much memory
0:04 was used to. So let's go over here and say "t0 = datetime.
0:11 and then we're gonna do this and then check.
0:13 So why not a little try
0:15 finally, hey? bring that in there.
0:19 And then we're going to say the change in time is as you would expect.
0:27 And then I'll just do a little print statement that says we created a crowd in however
0:31 much time, convert this to milliseconds,
0:33 so let's just see that. Here we go.
0:36 It took 459 milliseconds to create our 100,000 size crowd.
0:42 The other thing that we want to check,
0:43 though, is how big is the crowd?
0:48 So we'll just print out a little statement here, the size of the crowd,
0:52 we've got to get our size utility, and just like before,
0:59 we need to have this bit at the top,
1:02 so in case you're not using PyCharm,
1:06 things will still work. So here we're going to say,
1:14 "get the full size of our crowd". Remember,
1:17 this traverses the whole object graph and it's gonna print it out in megabytes.
1:21 So the "create_a_crowd" knows how long it takes,
1:23 and then we're just going to say how big it is.
1:27 Created a crowd in 400 milliseconds,
1:29 and the size of the crowd is 32 megabytes.
1:33 Alright, not bad at all.
1:36 This doesn't really mean a lot to me.
1:37 Like, What am I gonna compare this against? Is 32 MB's
1:40 good or bad? I mean,
1:41 it is 100,000 people with lots of information about them.
1:45 That's cool. And 400 milliseconds, also not too bad.
1:48 So we're gonna use this as our baseline and
1:51 we're gonna create two other versions of our person implementation that are gonna improve upon this
1:56 and actually make it better, both the crowd size created or the crowd created in
2:01 is gonna go down, and the crowd size is also gonna go down.