Mastering PyCharm Transcripts
Chapter: Performance and profiling
Lecture: Surveying the slow application
0:02 Let's look at this new little application I've imported and written
0:05 for talking about performance and profiling.
0:08 So this is not anything practical in any real sense of an application
0:12 but it does do a variety of different things
0:15 which may or may not seem slow.
0:18 So here we are in this program and I've set up a run profile
0:21 let's call it program(perf) to disambiguate
0:26 from all the other programs we have
0:28 and in here, for now it runs this function once,
0:30 we might run it a bunch of times later
0:33 and what it is, is you give it a string, usually a single word and you say
0:38 okay, I want to go and search a website using an http api, get some results back,
0:44 I want to go to the database and do some searches
0:48 sort of searching for this keyword here,
0:51 and then I'd also like to go and do some sort of
0:55 fake machine learning type thing here that's a computationaly intensive
0:59 and we're going to print out all the time that that takes,
1:03 like I, said this is not entirely fake, but it is somewhat useless.
1:08 So the things we're doing here don't make a lot of sense really,
1:11 it's just for us to do different things
1:13 where you might think about what part is fast, what part is slow.
1:17 So in this search part here, this really does go to a url and it builds up the url,
1:22 and it performs a search and then it converts the results back into objects.
1:27 Down here it actually is searching the transcripts
1:30 all the content on talkpython.fm
1:34 so when we say profiling, it will give us back the thing that had to do with profiling,
1:38 if we said and anvil, give us the stuff about anvil web apps and things like this.
1:43 So that's really cool and it goes and it performs the search with requests,
1:47 converts the results back,
1:49 basically gets the description for each episode that matches.
1:53 And then, let's go to data access I think that one runs next
1:57 we're going to create a database connection
2:00 and we're going to omit the details for a minute on that,
2:03 we're going to run a query based on this text sort of, kind of, not really,
2:08 and then we're going to just loop over
2:10 imagine 100 records came back
2:12 we're going to pretend to read those rows back from the database
2:14 and add them here and they we'll return that data.
2:17 And the details about reading rows, we're not talking about it yet.
2:21 And finally, here we're going to compute the analytics
2:25 so we're going to read some data and then do some more stuff here,
2:28 and then we're going to go and say given these two pieces of data
2:32 let's go and do some machine learning
2:37 that come up with the answer, some kind of index here.
2:39 We're going to try to figure out what parts of these methods I'm not showing you,
2:43 which ones are slow and which ones are fast,
2:46 how often we're calling them, things like that.
2:49 So I'll go and run this and then we'll turn on the profiling tools after.
2:52 You can see it takes a second to that first part
2:55 and then the db business is kind of fast
2:58 and then here I came up with this big long number
3:00 right here in this learning thing, I'll run it one more time,
3:06 you can see they are kind of similar
3:08 the overall operations, the the three operations
3:10 but inside the various things they do, not so evenly split.