 Okay, a viewer by the name of Connor Dunn asked this question. He wants to know how to compare the speed of any language, maybe time from start to finish of two or more languages in lending an algorithm to give a more concrete example, compare the quicksort algorithm in C and in Python. And we'll probably get to his quicksort algorithm in a future tutorial, but I just want to quickly show you how to compare the speed, basically time, how quick a program takes to run. And this is something I've shown in the past, but I don't mind going over again. And let's see, I have two files here with code. The first one is some C code. It's called math.c. I just called that because we're doing very basic math. We're adding one. We have a function here. The function creates an integer variable of zero. It will loop while that variable X is less than 10,000, adding one to X each time. So it will loop 10,000 times and print the output returning zero at the end of the function. So let's go ahead and save that. And let's use gcc to compile that. gcc math.c output I'll call math. And if we just dot slash math, it runs. It runs really quick. Let's do time dot slash math. And here you can see the output of time. It times how long it takes for the program to run. You have the user time and system time. And from what I've read, the user time is how long it is being processed by the CPU. And the system time is how long the operating system takes to do whatever it needs to do. So the best way from what I've read to, again, accurate time is to add the two together. I guess you also have this over here, this total time, which is a real time. And from what I've read, that's not... I've been told adding the first two numbers together is more accurate than that. I don't know if that's true or not. That's just something I've read. But let's run this program a few times because you're going to get a little bit different output each time. So this time we got 0.02, 0.02, and a total of 0.064 there. 0, 0.02, 0.049. 0, 0.01 there. So fairly consistent with at least the user time and the system time as being within 0.01 seconds there. Let's look at my second piece of code here, math.py. And same code, only written in Python 3. We have a variable, which is x, which equals 0, while x is less than 10,000. It's going to loop adding 1 to x each time, so it's going to loop 10,000 times and print the output. Let's go ahead and save that. And we'll just run it the first time.py there. It runs fairly quick. As far as the end user concerned, in this particular case, there is no difference. But if we time it out, you can see that that user time, that time in the processor is quite a bit higher. It was almost always 0 before and now it's 0.05 to 0.06. There's a 0.03. The user time, the operating system time is pretty much the same. You look at the total time, it's pretty much double, if not more on average. So that's very small. Obviously, the more you're going to calculate, the more of a difference it's going to make. So let's go ahead and let's edit our C code here. Instead of 10,000, let's add two zeros there so it will loop a million times. We'll recompile that. We'll say time, math, and run it. And as you can see, it's taking quite a bit longer because it's going to be 100 times as many loops. And we're about a little more than halfway there. Almost done and we are done. Okay, so now we got 0.22S for user, 1.88 for system, and a total of 19.26. So try to remember those numbers. 0.22, 1.8, and 19. Now let's go into our math.py and do the same thing here. And we'll run that through time. So this time we're running time with our Python script. Let's again remember 0.2, 1.8, and 19, just to get round rough numbers there. And we'll let this run. Okay, already it's feeling quite a bit slower. And again, this is a very basic example, but it's doing a lot of a very simple calculation over and over again. So this time, yeah, so a little bit, the total time was a little bit more, or about the same, 19. something. The user time and the system time have gone up. The user time, which was the CPU time before, was 0.22, and now it's 2.78, and the user time, which is the operating system time, went from 1.8 to 2.32. So still, I mean a few seconds difference. But again, if you're doing calculations that take like a day for your computer to calculate, it might take a day and see it might take three in Python. But I also want to point out, I always like to point this out that, yes, C is probably going to be faster for a lot of stuff than a scripting language such as Python, or Java, or PHP. But especially as programs get more complex, how you write things can make a big difference too. When I've worked on most projects I've worked on are small little things to accomplish tasks for myself. But I'll tell you, working on my Metal Bullets project, which is a first person shooter in HTML5, I wrote using Java script. I start doing stuff and the game would come into a halt. And then I just rewrite the code a little bit better, basically accomplishing the same task, but the game would actually start functioning again. I still have lots of problems with that because I'm a horrible programmer. But how you write program makes a big difference. And then also, there's also little things you can think of like this is doing a lot of printing to the screen. Now, if we were going to our code and not print the output to the screen and just run the code where it's still doing the calculations but not outputting every single line for every single loop, it would make a difference. We can change that in the code, but also as the end user, we can just pipe the standard output to a file even writing to the hard drive will speed things up. But we can also write to dev null. So let's go ahead and do that. So I'm going to say time and we'll say dot slash math. This is our C code. And I'm just going to pipe that into dev null. Look at that. The same code that probably took, you know, 20 seconds before took a fraction of a second now because writing to the screen takes a lot of time. It's basically every loop. It's got to stop right to the screen and then loop again. And the same thing would be true for our math.py. So a little bit slower. They're quite a bit slower still. So you look at our system. Let's run it again here. Yeah, it seems pretty consistent there. Let's do our C code a few times. So there, if you eliminate the printing to the screen, you can see here that it does make a rather big difference. So there's a lot of things to compare with. So there's a lot of things to compare rather than just what language you're writing in, but how you write stuff, but also the language you write. Both are important. What language you're writing in, but also how you write, and actually even how you compile in some cases. But that's beyond my scope of practice. But you can see here looking at the code, without printing the screen, piping everything to null, counting to a million in both languages is a lot faster in C. But again, in this particular short case, it's still fractions of a second. But again, in a bigger project, it could make a big difference. So I hope that answers the question a little bit more, but not really. It probably just confused things a little bit. Definitely, again, C code is faster. If you were the same programmer, equally familiar with both languages, and write both of them efficiently, obviously C is going to be faster. But if you're a crappy C programmer, but a good Python programmer, depending on what you're doing, you should be able to transport your code over with it being mostly the same. But let's just say you're a really bad C programmer, and you're a good Python programmer, you're probably better off writing the thing in Python because you're going to write it more efficiently, theoretically. There's a lot to look at. Anyway, before I keep repeating myself on how you can go back and forth on this, I just want to thank you for watching. Thank you to Connor Dunn for asking this question. And as always, please visit my website, filmsbychrist.com. That's Chris Decay. There should be a link in the description. And as always, I hope that you have a great day.