Python Memory Management and Tips Transcripts
Chapter: Memory and classes
Lecture: Is it a crowd?
0:00 If this was the entire program,
0:01 or at least the entire usage of person,
0:03 we're done. There's nothing really we gotta worry about,
0:06 but we're exploring memory and how that works.
0:09 So we want to make a bunch of these things, right?
0:11 So let's go and create a function called "create_a_crowd()" and it's gonna return a list
0:18 of person. I want to explore this in two ways.
0:25 First, how long does it take to actually create the crowd?
0:28 And then we're going to do it.
0:29 So first, let's just write like this, we're gonna return a list expression here, were gonna
0:34 create a person, it doesn't really matter what values we put in here.
0:40 I'll just say first and last,
0:43 and this will be "datetime.datetime.now()",
0:48 and let's say they make $5000 a year.
0:50 Sure, there would be some variation,
0:52 but honestly, it doesn't matter.
0:53 Then we'll just say "for whatever in range from 1 to 100,000" and let's go over
1:03 here and say "crowd = create_a_crowd()".
1:08 You're gonna see that it runs. It does.
1:10 Let's print out the length of crowd and the first item of crowd.
1:18 There we go. We have, oh, we're off by one.
1:21 We have 99,999 and we have a "PersonNaive" object,
1:25 even though, of course, we said person, currently the implementation of that is what
1:30 it is. So let me do a plus one, or we could more easily do it
1:35 like this I guess, from zero. There we go.
1:38 There's our 100,000. Alright, we've created crowd,
1:41 Now the next thing to ask is how much memory did we use and how long did it take?