Python for the .NET Developer Transcripts
Chapter: Web frameworks
Lecture: ASP.NET and Flask performance compared

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Earlier, I talked a little bit about performance, and that Python is actually an incredible framework or language to write web applications in.
0:10 I said, Look, it may seem like .NET is incredibly fast. It compiles to IL which it compiles to machine instructions. How could it possibly
0:19 not just blow Python out of the water? And there's certain operations where .NET absolutely does especially numerical computation
0:26 if, big if, if you're not using the scientific libraries in Python but you're just trying to do straight math. C# is way faster, no doubt.
0:34 But that probably doesn't matter to you. You probably just want your web app to go super fast. The folks over at Microsoft have done
0:40 a ton of work to make web processing way faster in .NET. Back in the a speed .NET web form days where it was regular .NET, it was so much
0:50 data being created and passed around. It was terribly slow. They've done some really good work. And now, if we go and hit local host, guitar
0:57 /electric with the right port on it and we do this a bunch of times you will see that the .NET Core 3 version which is what we are running
1:05 the C# one. It'll blaze. It will do that whole thing that non database driven one in 3.5 milliseconds per request. Or it will do a 1000 requests
1:16 in 3.5 second for example. That is really good right. Would you be surprised to hear that Python does the same thing at 2.6 milliseconds?
1:24 Yeah, not only is it not that bad it's faster. I don't even understand how it is faster. It shouldn't be faster than the compiled
1:34 stuff that's happening in C# side. But it is. So I think this is pretty awesome. Going to show you a little program that you
1:41 can use to check this for yourself. Over here, in ch_07, I have now added the speed_test. The way it works doesn't really matter.
1:49 You have to have it in your requirement which I've added here in requests. But what we are going to do is going to run this against our website.
1:55 Now. Also, another quick note about running these websites here. See how this one is marked as a sorcerer's blue and this one is not.
2:04 Because these have the same stuff in them if you mark them both as it, the first one is going to be where the actual implementation comes from.
2:12 So if you want to run this one you got to unmark, right click, um mark directory as unmark as sources root. You can't have them both to set
2:19 to run at the same time. It's kind of a unfortunate thing. Very rarely you will actually have these together like this except for demo code
2:26 which of coarse this is. But let met go run this app first. That was going to be running here. Make sure it works. Looks like a champ. Okay.
2:38 Here is the scope of the electric guitars. Here is what we are going to get. Now that is running. Now let's also go run this speed test down here.
2:48 Make sure you give a space here or a Python is weird and I'm trying to open it. Let's say the URL is that. Let's do this 100 times. Go request that.
2:58 Now remember, this is the Python version. Boom. 2.98 milliseconds. Run it again. Ah, there is that. Don't forget the space.
3:10 End times, 4 seconds this time. Better run it a little bit more I guess. There we go. 2.9. Pretty good.
3:21 We got a lot going on with screen recording and stuff so it's probably slowing it down a little bit. But nonetheless, that is blazing fast.
3:27 That is faster than .NET. Doing quite a bit too. Remember it's doing it's little query it's doing it's filter, returning stuff.
3:34 It's probably even faster if we don't ask for the electric, but we ask for all. And it is about the same. It doesn't really matter does it.
3:44 But nonetheless, its pretty impressive. Yeah, I think it is a little messed up. I don't understand what it's doing there.
3:52 Anyway, it's really cool how quick and fast this is. And you can use this speed test app to test any website, right?
3:58 You can put that against Google if you like. You can try it on my site. 10 times. Pretty good. Now, why is it so slow?
4:11 It's so slow because it's far away across the internet. But whatever. You know, you can't help with PING time.
4:15 Nonetheless, it's pretty cool you can test your app locally with that. Oh, one more thing! I did forget. I did forget. Uh, this cannot be helping.
4:25 Sorry, let's turn that off. I think I had turned that off as well. Let's try again. Ah, there we go! There's that 2.5 I was looking at.
4:35 We had the debug mode and so a lot of extra stuff was slowing down in there. Perfect! Finally, you might be thinking, okay
4:44 Python is faster here, but that's because it's like this fake little app. I think it's doing quite a bit in there for a standard web app.
4:51 But nonetheless, maybe it's maybe it is doing more. So let me show you real output from a real production server, that is doing way, way, way, more.
5:00 Here is a very small segment of the logs on training.talkpython.fm and these pages do a ridiculous amount of database queries.
5:10 Got to figure out what the user is. Got to go back to get a bunch of courses. Got to figure out if you finished watching these courses.
5:16 All kinds of stuff as you are you interacting with it once have you marked it finished. What are your preferences?
5:21 Do you want the video to play at 1.25 speed? So there are a ton of stuff happening here. Look at some of these numbers.
5:27 Yeah, some of these are like a hundred milliseconds. And you know, either thats because the server hasn't really hit that page very often
5:34 or like the entrepreneurs one, just a huge huge page. So it just takes a little bit of time to generate it. But look at the stuff on the bottom.
5:41 My course summaries. Get the free courses. Or this is probably the api, that the app the mobile app your using. 11 seconds
5:50 7 milliseconds, 10 milliseconds, 46 for log in 6 milliseconds to render the log in page. or to render the account page.
5:58 25 milliseconds. This is real stuff. In production. On linux. On a pretty small and cheap server. Right, these are pretty solid numbers folks.
6:08 Given the amount of net back and fourth with the database and other types of things that we are doing here.


Talk Python's Mastodon Michael Kennedy's Mastodon