Just how Slow is Python?

  Рет қаралды 9,945

The Code Guy

5 күн бұрын

In this video, I dive into the speed differences between Python and C++. I write and compare the same program in both languages, revealing why C++ outperforms Python. Despite its performance drawbacks, Python remains incredibly popular. I explain the reasons behind its continued success and share practical tips to enhance Python's speed using better coding practices. Tune in to learn more and boost your Python performance!
Do you need thumbnails? Get in touch with my artist here:
TrueRedTFox
Stock Footage and sound effects: - (Referral link)
ArtlistIO : artlist.io/Guy-1799812

Пікірлер: 149
@АртёмМакаров-к3д
@АртёмМакаров-к3д Күн бұрын
I think C++ is way more faster than 11x times. In your example printing every single game in the terminal actually creates very significant bottleneck.
@the_code_guy
@the_code_guy 8 сағат бұрын
it does and surprisingly so, but it's not tic tac toe unless I can see it playing. thanks for your note and for watching!
@rickzalman4136
@rickzalman4136 3 күн бұрын
Because Python is a interpreted language, it has to check every line of code ,at the same time that it is translating it into machine code at runtime. Plus every thing in Python is a object of some type(int, float, str, list, tuple, dict). On my smartphone a string(str) object that contains a empty string has a memory size of 25 bytes. s = "" # empty string print(sys.getsizeof(s)) # 25 bytes of memory . ####### x = 2 # integer print(sys.getsizeof(x)) # 16 bytes of memory. Python uses a lot of memory overhead because everything is a object, which also makes Python sluggish.
@the_code_guy
@the_code_guy 3 күн бұрын
Yes the lack of native support for primatives is a big contributing factor. As is the interpretation of the pythin byte code.
@asierxs02
@asierxs02 2 күн бұрын
This is not true, cpython compiles each source file into its own bytecode language which it then interprets. The reason why python is slow and takes so much memory is because of how everything is allocated on the heap and represented as a dictionary. To give you a better idea, an instance of class Foo is allocated on the heap when calling init, but when you declare said class, an instance of class Type is allocated on the heap, all backed by key value pairs (dictionaries). This indirection is what allows Python's API to be so flexible
@honkhonk8009
@honkhonk8009 Күн бұрын
Not even. It uses JIT and converts it into bytecode
@glamoagency5642
@glamoagency5642 Күн бұрын
​​​@@honkhonk8009not even. You have it backwards, between the meaning of bytecode translation and JIT. Bytecode in a .pyc ifile is a non-executable intermediate representation fully analogous to Java's .class files. Said bytecode is then either interpreted by a Python VM (JVM for Java, this the old school way, before JITs), or Just In Time compiled to machine code (skipping the assembler) at runtime. The latest 3.13 standard Python implementation finally has an optional JIT compiler. The Python binary needs to built for it from C source, --with-jit, it isn't a runtime option.
@asierxs02
@asierxs02 Күн бұрын
@@honkhonk8009 a JIT means just in time compiler which involves compiling code into machine code while running. CPython has nothing like this. PyPy on the other hand is an alternative Python implementation that does have a JIT compiler. You might be confusing the fact that CPython compiles a file to bytecode when it comes across an import statement.
@tordjarv3802
@tordjarv3802 2 күн бұрын
I don’t think that development speed in Python is that much faster. I think the main reason it’s faster for you is that you are more familiar with Python than C++. In my experience, because Python is duck typed (it follows the principle “it quacks like a duck and it walks like a duck so let’s call it a duck”) you can have really weird bugs that could never happen in a statically typed language like C++. I’m pretty certain that development time is roughly the same for experienced developers in both languages.
@architmishra015
@architmishra015 2 күн бұрын
The boiler code in languages like C++ and Java just inherently makes them "slow" in development time. And plus you need time to compile the code too (which isn't always fast)
@ATtiny13a-PU
@ATtiny13a-PU 2 күн бұрын
Подписываюсь до вашими словами чёрной ручкой! В уже настроенной среде на C++ программировать также быстро, как и на Python, но когда дело касается оптимизации, то делать это в разы легче на C++, хоть можно достичь примерно равной производительности, если перевести большую часть кода Python на нативный.
@Steven-tw7iz
@Steven-tw7iz 2 күн бұрын
@@architmishra015 while there is more typing for C++ and Java, the argument is the extra time spent typing up front pays off in less debugging time later on because these statically typed languages can’t even have any bugs of the class that python can around typing. It’s the same argument rust has for security. “You spend extra time fighting the borrow checker, so you don’t have to deal with security issues later”
@noname-zt2zk
@noname-zt2zk 2 күн бұрын
Nah python is defo faster for development
@ATtiny13a-PU
@ATtiny13a-PU 2 күн бұрын
@@noname-zt2zk, умеешь ли ты программировать на C++? Насколько у тебя большой опыт? Имеешь ли ты свой пул библиотеки и паттернов проектирования, чтобы решать задачи быстрее? Как вообще можно говорить, что питон быстрее для разработчика, если в нём нет даже перегрузки оператора... если и говорить о языках для быстрого прототипирования, есть варианты лучше питона.
@Scudmaster11
@Scudmaster11 5 күн бұрын
Lua is 16.67x faster... native is around 350x faster then python
@the_code_guy
@the_code_guy 4 күн бұрын
I heard lua was fast, haven't played with it yet, though I do use an app written in it.
@kaiosantos-g3t
@kaiosantos-g3t 2 күн бұрын
@@the_code_guy I'm new to programming, so I can't make any real test yet, but with a simple prime calculation, lua was about 4-4.5 times faster. Plus you can use LUAJITI or Pallene( compile lua modules AOT), wich make it's performance closer to java/C# and javascript. Although with javascript it could have a bigger difference for worst of for the better when starting to allocate a lot of memory.
@stavros222
@stavros222 2 күн бұрын
C is faster not to mention assembly
@ntre.
@ntre. 2 күн бұрын
@@stavros222 the c compiler optimizes so much that your pure asm code is probs worse than c
@stavros222
@stavros222 2 күн бұрын
@@ntre. in theory pure asm should be faster
@fischi9129
@fischi9129 Күн бұрын
So... why were classes needed for Tic Tac Toe tho? I'm really confused..... Also guardrails are not the whole story here. You can easily safely iterste over an array in Cpp for instance, std::array is suggested there. And the performance hit is not even close. Most guardrails can and should have little to no imoact at all
@the_code_guy
@the_code_guy Күн бұрын
They weren't the making of tic tac toe in python was really a rounding off my beginners series and putting everything into practice. So then when I ported it wanted to keep to the same structure as much as possible. You are right it's a collection of multiple things that make it slower, such a dynamic typing, interpreted, GC. Thanks for watching!
@PixelOutlaw
@PixelOutlaw 2 күн бұрын
As a Common Lisp guy they really dropped the ball with Python. It is possible to have a very efficient dynamically typed compiled programming language. Try Steel Bank Common Lisp. Using the (decompile ... ) expression, you can even see what each function gets compiled to in assembly after being immediately interpreted. And it does this each time it encounters a new expression so you're not recompiling the entire program.
@lemna9138
@lemna9138 2 күн бұрын
the inaccuracies pain me
@the_code_guy
@the_code_guy 2 күн бұрын
Please share them so I can post corrections
@mahdoosh1907
@mahdoosh1907 Күн бұрын
​@@the_code_guy interpreted languages do not convert into machine code (it might be possible but not commonly used), it is more of a simulation. as if you add 2 and 2 by saying: if input is 2+2 then return 4 instead of actually adding the numbers.
@Seedx
@Seedx Күн бұрын
​@mahdoosh1907 they convert to bytecode which is then interpreted, but yeah not machine code
@FastRomanianGypsies
@FastRomanianGypsies Күн бұрын
@@mahdoosh1907 CPUs can only run machine code last I checked
@alexanderdelguidice4660
@alexanderdelguidice4660 2 күн бұрын
I like python more than c becuase python usually doesn't segfault when you do something slightly wrong (unless you are messing with things you shouldn't be). Python is not the best (by a long shot) but it gets the job done and is a good place to start when getting into programming.
@the_code_guy
@the_code_guy 2 күн бұрын
Couldn't agree more. This was not intended to be an attack on python.
@akilelamin
@akilelamin Күн бұрын
I love python to bro. Soon hardware will be so fast it wont matter anyway.
@alexanderdelguidice4660
@alexanderdelguidice4660 Күн бұрын
@@akilelamin Hardware progress is slowing down a lot. We are very close to reaching the point where physics doesn't allow us to go any smaller, so transister count can't increase any more per die size. What your saying won't happen unless 1) we make a massive breakthrough AND 2) we ditch x86 for a better alternative.
@akilelamin
@akilelamin Күн бұрын
@@alexanderdelguidice4660 time to go quantum baby 😎, My point is that I believe more breakthroughs are coming. May be learn to produce power more efficiently or something 🤷‍♀. Plenty of improvement left to make.
@alexandermendivil7464
@alexandermendivil7464 Күн бұрын
@@akilelamin Even though what you are saying could happen, as a programmer you shouldn't aspire letting the hardware handle everything, I think that's why a lot of software nowadays (especially games) have an insane usage on memory and cpu when I guess a lot of cases those usage could be way lower
@praus
@praus Күн бұрын
I think this video brings up great points. Speed can sometimes be a huge issue. Often it’s not. Often the ease of use is the important thing. If I’m a scientist and I need to create a quick little program to help organize and perform mathematical operations on my 500 instances of data, Python is just fine. I probably don’t care if that execution took 30 seconds vs. 10 seconds. I just need it done and I don’t want to spend all day coding. On the other hand, if I’m programming a AAA game that needs every last bit of performance, I’ll almost definitely be using C++ or similar.
@the_code_guy
@the_code_guy Күн бұрын
Spot on. I use python. For most things when as fast as I can make it is fast enough. If I need more speed I can change the design or use python or pick a different tool. Right tool for the job. Thanks for your comment and for watching!
@cookie_of_nine
@cookie_of_nine 8 сағат бұрын
I have a feeling something is hobbling your C++ performance (Did you build in release mode?). Either that or the windows terminal is causing ridiculous slowdown. To compare, I followed along building my own Go version using the previous Python video, and got a ~30s runtime. Details: - 4-core i3-1115G4 @ 4.1Ghz (11th Gen Intel laptop cpu) - Running on Linux in a VM on a ChromeOS - Single threaded solution Go by default optimizes the code (notably, it's default is to optimize without breaking most debugging / tools), so it seems to me that you may have accidentally built the C++ code in a non-release mode (the default for CMake).
@the_code_guy
@the_code_guy 7 сағат бұрын
I think it was the windows terminal, with output suppressed it flew. I also had to control the terminal cursor position to overwrite the previous output so it didn’t scroll. this was a tone faster than clearing there terminal which was crazy slow. I really do want to give go a look at some point soon, I’ve heard a lot of good things about it. Thanks for following along and sharing your results!
@cookie_of_nine
@cookie_of_nine 7 сағат бұрын
@@the_code_guy Ok, I knew the windows terminal did suck, but wow. I was just a little surprised that my simple translation of your python code ended up being 3x faster than C++ when my result was on a VM on an underpowered laptop, other differences between our setups not withstanding. Looking at my Go profile, one of the biggest time sinks (as expected) is MiniMax, which could probably benefit from some memoization, since after the first move it's likely already computed answers for every possible outcome once. I'm not sure if python's built-in memoization will work for you, but if it does, it should scream after a one line change.
@Tekay37
@Tekay37 Күн бұрын
A few things you could do to extend on this: 1) also try Odin and see how fast you can develop the game there. 2) compile the python code in mojo and see if you can get a significant speedup.
@the_code_guy
@the_code_guy Күн бұрын
Thanks for the suggestions and for watching!
@Fiercesoulking
@Fiercesoulking 16 сағат бұрын
I have the feeling you were still in debug mode or didn't turn on the optimizer by my experience its more like 20 to 60x times faster
@the_code_guy
@the_code_guy 8 сағат бұрын
It would have been significantly faster if I did not print to the screen. I don't think I left it in debug but it is possible, it's been a while. thanks for your feedback and for watching!
@bobamos8508
@bobamos8508 Күн бұрын
Of course if you try to write c++ in a python way, développement time will be slower. But the opposite is also true, if you are used to think like the computer and control your state, python is actually slower. I mainly use c#, but i feel waaaay more comfortable writing c++ than python since at larger scale python will abstract and hide problems.
@the_code_guy
@the_code_guy 8 сағат бұрын
I have to disagree, there is a lot more to think about in c++ code and if you are like me you will make mistakes. python is way more forgiving in telling you what you just broke. it has been a while and I would definitely get quicker over time as I mention. I actually really enjoyed the experience, because it really did make me think more about so many aspects of the code. I have coded in a lot of languages over the years and python is way faster for prototyping it does so much for you. Thanks for your comment and for watching!
@Devoodie
@Devoodie Күн бұрын
"C++ Code is not run on the machine directly..." doesnt make sense. Its not run remotely from a different computer. Its a inaccurate way to describe compiled vs interpreted languages.
@the_code_guy
@the_code_guy 8 сағат бұрын
thanks for the feedback and for watching! Yes I should have been a lot more careful with my words inheinsight.
@johnpekkala6941
@johnpekkala6941 2 күн бұрын
Python is a really nice language but it is also the slowest of them all so in order to get any performance out from it whatsoever you need to also write a complete backend in something like C++ or Rust and use Python just as a control interface to call the undelying C++/Rust code like a syntactic sugar on top, C++/Rust being what is then doing the actual work under the hood. This is the case with Tensorflow for example. Python by itself would be way to slow to operate for example self driving cars that need to react in 1/100000 of a second to prevent an accident in critical situations so C++ is what does the actual work here, not Python, is just used as the "operator interface" to make it easier to use. In short Python is nice syntax wise but way to slow to be used by itself for anything more complex then short simple tasks. It is more of a "control language" or whatever you would call it.
@federicobau8651
@federicobau8651 2 күн бұрын
I really think you are talking a bunch of crap. Are you even a developer? You need to pick up the right tool for your job. You made and example that suits c++ or rust and with that concluded that python is good for "short simple task"... emhh what? Is used largely in production code as web back end with very large code base and surely not short task, working just fine. In data science, data visualization, machine learning and so on. You are considering a very narrow perspective and taking conclusion based on your ignorance.
@stivenmolina4075
@stivenmolina4075 2 күн бұрын
95% of programs dont care if the time to do a task is 0.003 of 0.0003 seconds so most of the time speed is just not necessary, when it is go with something low level and fast, when it is not needed then just go with whatever tool you are more productive with
@the_code_guy
@the_code_guy 2 күн бұрын
I actually disagree, some things in python are fast, for instance dictionaries so building a system around those and python can absolutely scale. Would it be the most cost effective scaling no, but way too few developers care about efficiency these days.
@Love-Kumar143
@Love-Kumar143 4 күн бұрын
Amazing Content Buddy 🙌
@the_code_guy
@the_code_guy 4 күн бұрын
Thank you, glad you like it.
@marcof1430
@marcof1430 2 күн бұрын
It's true: Python is fast to program. I think the best is using Python for fast development or prototype. And maybe when you are sure and need more performance switch to low level language..
@the_code_guy
@the_code_guy 2 күн бұрын
Totally agree. In most cases it is however fast enough.
@CaritasGothKaraoke
@CaritasGothKaraoke 2 күн бұрын
I find Perl faster to develop in _and_ it executes faster than Python. CPAN is just as robust a library of extensions, and XS modules share the “this part runs in C” advantage. And I also find Perl to be more readable than python. You just have to not try and write C in Perl, which too many people do, and instead embrace Perl idioms like postfix conditionals. But perl’s lack of good marketing department means I’m stuck with janky python instead because nobody hires Perl guys anymore. It just endlessly annoys me that there came a big shift in the Perl community towards some hamfisted idea of “modern” including using crap like Moose when you don’t need it one bit and it incurs overhead, left the expressiveness and readability and fast development behind but then that stuff became why everyone embraced python.
@the_code_guy
@the_code_guy 2 күн бұрын
Don't know a lot about pearl but I would that there is nothing wrong with the readability of python if it's written right. Live a list comprehension wit 5 levels of interaction is just a bad idea and so will be hard to read. Python probably gives you more opportunity to right bad code but you as the developer are ultimately responsible for that.
@DeveloperLinux-c3m
@DeveloperLinux-c3m 4 күн бұрын
What do you think about java bro? just curious to know your opinion in speed
@the_code_guy
@the_code_guy 4 күн бұрын
It's been a while since I last wrote any Java, so some of this may be stale. If I remember correctly it roughly sits smack bang in the middle between C++ and python in terms of performance. So You can expect to be someware in the order of 5 times(actual numbers may very widely depending on what you are doing and how optimised the langtuiage is for it) faster than python. I also recall that the spin up time for the Java vm could be woefuly slow (4 - 8 seconds) so if you are running stop start workloads python could actually beat it in some fast execution scenarios. But if you are running a program that is always up taking requests for instance it will be way faster. Java also has type safety and won't let you do silly things with memory so debugging will be way faster than C++, they syntax is still pretty heavy so you will write more code than python, less than C++ (Mainly becuse you don't have to deal with header files). I could be wrong here, but I also don't think there is a direct way of dipping in and out of compiled c, like you can with python. You can of couse invoke other programs on the system and read the results. There are also ways of transpiling Jave to c++. Sorry for war and peace, got a bit carried away. Hope this helps and thanks for watching!
@seansingh4421
@seansingh4421 2 күн бұрын
What I know about Java is that it’s really powerful and it powers some of the most powerful projects like elasticsearch, opensearch and others
@Luix
@Luix 2 күн бұрын
Go is as fast to develop as Python and very performant
@the_code_guy
@the_code_guy 2 күн бұрын
Never used go, but it is on the list of languages I'd like to play with.
@RoboGameOfficial
@RoboGameOfficial Күн бұрын
comparing a compiled language to an interpreted language is like comparing a tortoise to a hare
@the_code_guy
@the_code_guy Күн бұрын
I did say it was somewhat unfair... Thanks ks for watching!
@federicobau8651
@federicobau8651 2 күн бұрын
Mate is all depend what you are doing. In web development for example 80% company requirements a language like python is more than enough. Something being "slower" than something else it doesn't make it "absolute" slow. All depends and is relative with what you comparing with. C/C++ OFF COURSE are faster but ARE NOT used for build web frameworks at 99% of the cases (yes the underlying software are, but whats under is already not the web framework..is another lower layer) Having said that i read few comments and uff ... the amount of ignorance is scary.
@the_code_guy
@the_code_guy 2 күн бұрын
Please don't get me wrong I love python and my closing thoughts in the video is that python can be fast enough for what you need. I use it regularly and will continue too. From my perspective it's all bout choosing the right tool for the job and without knowledge like this you will not be able to choose.
@federicobau8651
@federicobau8651 2 күн бұрын
@@the_code_guy Well I read and answer few comment below this video. I can say that majority have twisted and confused ideas and honestly by the way you answered them, either you just want to agree with them or you are also have (hence have such followers). I don't have problem with the video itself (well i could say that these benchmark shouldn't be taken too serioulsy) I wrote my comment more towards others that commented in your video. Generally speaking who generalize or stand aside one programming language I see them as pretty bad developers or at least very limited one (hence if they don't change their mentality you ll see the difference in terms of technical skill in few years). The most notorious example are devs that free shit on PHP, Java, Python being slow , C ugly and so on. as developer we shouldn't "take a side" or have a "favourite language"... what the fuck is this? YOu can have a favourity ice cream flavour but not a favourite programming language (but unfortunnally people do think this way)..So do these people favorite "a paint brush" and uses only paints brushes for build the whole house? Wouldn't they use, screwdrivers, cranes, drills and so on? For example take PHP i think is has a limited usages yes but it can shine if you know how to use it. (most notably it's 'stateless' behavior can be used to scale apps like crazy) However, where it shines is also very it can lack, PHP devs that tries to "add memory" to PHP (memcache for example) are left short by other languages such as Java, Python, (ruby? pretty sure is not stateless) , NodeJs, GO. Using Python for web deve for example, using Django is an amazing experience, as you said is abstract and high level really makes it fun and 90% of the time will serve well. However if your "back-end" server is something that needs to compute like crazy.. take elasticsearch for example than Java is probably better.. Or...all docker and kubernetes back ends are basically mainly in Go (there are many other languages, Python but pretty sure C or C++) and is SUPER FAST. Now, re-wriite that in Python --> good fucking luck. But again.. who goes around and say "Python is slow because is SLOWER than C++" really get things mixed up. Is like saying "Mitsubishi Lancer evo is slow because is slower than a Ferrari".. well sure but is a Mitsubishi Lancer evo slow? don't think so. However, would youu go for a nice Mountain rally with a Ferrari? don't think so. all is relative in what you compare A with B and in which context you looking at it.. Finally man, all these discussion for what? How many times are we developer REALLY in control ? If so probably not so much. When we do our little un-known project that we ll probably leave after a week and no one cares? We normally work FOR COMPANIES witch have most of cases an already established code base, if you got the job and they are working with pyhton guess what? you ll be working with python. If they work with PHP.. or Java or C++ ,, all your opinion dont matter much .. I personally did have experience on see a team chooosing a new programming language or better re-write in a new programminng language few times. That was mainly the Tech Lead decision and convinced managers. Guess what? He fucking mistake.. took a Java Legacy code and wanted to re-write in PHP. while was already half done in GO (and was amazing) by the previous tech lead. HIs reason was "Because here we know only PHP" Half way, they noticed that Java legacy code has a always running thread that is outisde of web framework, always alive and doing "jobs" --> Boom php can't do that (without stupid crazy workarouunds or hacks) ALl the sudden the Half-rewrote GO was the PERFECT choice.. why? (go cough .. rout...cough cought ine...) Hence: Programming language == tool Projects == set of tool if you stick with one tool, you stick it up your arse soon or later.
@OxibanCraft
@OxibanCraft 2 күн бұрын
I know that most of your viewers are coming from a strictly IT background, but it's important to remember that there is a whole world of computational applications out there where there is no real substitude for the vast Python ecosystem. Being able to switch from algebraic computations to solving coupled systems of differential equations numerically, then compiling a video and uploading it to KZbin in a single jupyter notebook is not something you get from any other language out there. Given the abundance of highly optimized C based libraries for matrizes and the likes I have yet to encounter a situation where Python was too slow to use effectively.
@the_code_guy
@the_code_guy 2 күн бұрын
I agree and I say this at the end of the video. I genuinely love python for the ability to get stuff done fast. This is not going to stop me using python it was just an exercise because I thought it was interesting.
@Heheh01737
@Heheh01737 2 күн бұрын
People really just love hating python i mean the point he made we can basically use libraries written in c or c++ like pyqt5 and many other makes its just normal like a whole music player basically a clone of spotify runs in 0.37 sec that i made with some async and optimisations and i am not that good so pls just stop hating it😭.
@the_code_guy
@the_code_guy 2 күн бұрын
Please don't get me wrong. It was not my intention to hate on python it is a dream to code in a I genuinely love how fast I can code In it. They are also trying to improve the performance all the time. But some of the design delicious do make it very slow.
@custardtart1312
@custardtart1312 12 сағат бұрын
Something cannot be 994% slower. That is a misuse of percentages. Please edit.
@the_code_guy
@the_code_guy 8 сағат бұрын
Those slower calculations are a real thing. But I do agree they look kind of absurd. Thanks for watching!
@davef21370
@davef21370 Күн бұрын
C++ if you need the speed. Python for everything else.
@the_code_guy
@the_code_guy Күн бұрын
Right tool for the job, thanks for watching!
@giorgiobarchiesi5003
@giorgiobarchiesi5003 10 сағат бұрын
Interesting, but 200 lines of code is a script, not a program. Let’s talk about 20000 lines of code, or more, that our customer must rely on, and let’s ask ourselves if we can make it robust without strict typing.
@the_code_guy
@the_code_guy 7 сағат бұрын
I have to agree with you. I’m actually not a fan of dynamic typing. On the large code base I work on we used to prefix a variable with a letter indicating the type. since type annotations came in it’s not so much of a problem as the ide will validate if you switch types that disagree with annotations. For the cost of dynamic typing I do not actually get why languages would implement it. Using the annotations completely defeats the point. thanks for your reply and for watching!
@czebosak
@czebosak Күн бұрын
Character count is irrelevant, I can write at over 100 wpm but I don't code at that speed, because I need to think. What really matters is how much you need to think, Python might have more helper functions that make your code simpler, which means faster writing speed. You didn't mention the garbage collector which is one of the biggest reasons for Pythons fast writing speed, you don't even need to think about memory management. 2:55 No, in C and C++ you always know how big the data is, this would never happen in the real world. 3:36 Flexibility? This is a really big performance hit and you don't need this 99.9999% of the time and even if you do and most static languages have dynamic types. Line != line, you might have had more complex lines in your python code and you counted header files as lines, you usually copy lines to header files, btw how did you get such big header files for such a small project? I support the argument, but I think you've missed your points.
@the_code_guy
@the_code_guy 8 сағат бұрын
You are right I used it because I wrote the code with the same structure and it was an easier thing to visualise than things like think time. There is a tonne more thinking in c because the language does a lot less inherently for you. The big thing for me though is the guard rails the amount of debugging I had to do was a lot. Memory management wasn't really a huge deal because I just reserved a 9 slot byte array on the stack and reused it between games something you just can’t do in other languages like python. the header files were because of the class declarations and this was mainly because when I wrote tic tac toe in python it was to bring my beginner series to a close and so I wanted too show ooo, in practice you wouldn’t have written it entirely like this. hope this helps and thank you for your thoughtful response and for watching!
@chpsilva
@chpsilva Күн бұрын
The grass in my garden is faster than Python.
@the_code_guy
@the_code_guy Күн бұрын
😂
@dvidsilva
@dvidsilva 2 күн бұрын
Cries in nodejs
@sm1522
@sm1522 17 сағат бұрын
12 hours 🤯
@the_code_guy
@the_code_guy 8 сағат бұрын
It’s been a while. Thanks for watching!
@alexengineering3754
@alexengineering3754 2 күн бұрын
Python is faster, if you use powerful libraries like numpy because they are highly optimized. If you are the guy who want to build everything from scratch, python is a bad choice. But if you just have a lot of data and want to do some mathe or maybe need a simple solution python is great.
@the_code_guy
@the_code_guy 2 күн бұрын
I agree some things in python are fast. I have built highly scalable systems around dictionaries for I stance.
@RalfPinkaire-f7w
@RalfPinkaire-f7w 2 күн бұрын
Ate you sure you're a code guy? This is so flawed on so many levels, not least the lack of libraries needed for tic tac toe or the fact you used a once off makefile (give it take) as a percentage code increase indicator. Absolute garbage.
@the_code_guy
@the_code_guy Күн бұрын
sorry you did’t like it.the reason for the number of library’s was to keep the code structure the same as the python version so that the number of lines of code had meaning. it could have absolutely vpbeen written without libs or objects and in fewer lines of code.
@shmuel-k
@shmuel-k 2 күн бұрын
You probably shouldn't benchmark them at the same time 😊. Will skew performance.
@the_code_guy
@the_code_guy 2 күн бұрын
I did run them separately too and they results were comparable. The main reason to run them side by side was to give the impression. Of a race on the video.
@shmuel-k
@shmuel-k Күн бұрын
Ah, cool!
@pgpython
@pgpython 2 күн бұрын
When people say python is slow what you have to bear in mind is that you are trading that for maintainability of code. In other words to get the same result you end up writing less lines of python code. That is less chance of bugs being found in the codebase. Less lines of code that need to be maintained. Also you also have to ask the question is the performance good enough. Who cares if the same program runs in python in 0.3ms and it runs in c 0.03ms no one will thank you for the performance difference when it isn't even noticed.
@the_code_guy
@the_code_guy Күн бұрын
totally agree
@szymmarcinkowski
@szymmarcinkowski Күн бұрын
Try Go
@the_code_guy
@the_code_guy Күн бұрын
that is a language I do want to try.
@eagle32349
@eagle32349 2 күн бұрын
Code being slow is always a skill issue, saying that speed is irrelevant for the purposes of a given program is always an excuse. I know it sounds cheap, but imagine when computers were 30,000,000 times slower, had the memory of a gold fish and were programmed by hand on paper, speed was the difference between 3 minutes and 3 months, for things your code would be doing with 0 of the efficiency. No one likes slow...anything, so don't make it slow out of laziness, make it fast out of passion. Just because computers can execute 3 billion instructions per second and have billions of bytes of Ram and more of general storage, doesn't mean you have free access to hog all of it. Just because you write fast, doesn't mean what you write has the quality of anything given better thought behind it, like a plan for example, cuz I know people who type a line faster than they calculate addition of 1 to 2 digit numbers.
@federicobau8651
@federicobau8651 2 күн бұрын
You are mixing arguments. Yes there are some bad developers that due to their negligence makes un performant code, but that doesnt mean that there arent some prog language faster than others! Off course c++ or rust , go and even java as base line run faster than languages like python, PHP or javascript regardless of who wrotes it.
@the_code_guy
@the_code_guy 2 күн бұрын
I totally agree with you. I have a huge passion for performance. But if you are running stuff in the cloud written in python Vs c++ c is going to be faster and cheaper in most cases. This was designed to be more an education piece than trying to justify slow code.
@eagle32349
@eagle32349 2 күн бұрын
@@the_code_guy Yeah, although I was using “you”, I was more referring to the ones who do indeed justify it, when they are just excusing it. The “mix” of arguments is just how far the excuses extend to. It’s not even really meant to be something that insults them, just something showing off how quickly-written, poorly-thought out code affects everything it touches, and how people back in the day learned to avoid falling into it the hard way. Unless a universal programming language is made, there will be differences between languages, entirely because those languages aren’t written the same way, underneath nor above, and never will, most likely. But excusing the potentially abhorrent design or implementation of your favourite language, while acknowledging that others are faster, and potentially better, and not switching to it instead (and generally testing how much you like it), is literally a skill issue. That is something so stupidly easy, that you shouldn’t even argue against it, since it just digs your hole deeper. What I generally am against is arguments backed-up by excuses. When defending your argument, it is an awful experience for your opponent when you only use excuses. Obviously they wouldn’t have a way to defend against it, because the only way would be to match the excuses, which can then be used as the counter argument “Sloppy Logic”, by you, which puts your opponent in a chokehold which they can’t get out of, even though they probably had the more logical, and realistic, argument. This manipulation tactic is how excuses work, and have been since they were made. It’s Twitter behaviour perfected.
@vidal9747
@vidal9747 2 күн бұрын
The real problem in C is bad tooling
@the_code_guy
@the_code_guy 2 күн бұрын
There is a scary lack of a modern build system around python. Not sure what else you would be refering to?
@vidal9747
@vidal9747 2 күн бұрын
@@the_code_guy Most people put third party C/C++ code in their projects. There is no good and default package manager that handles versioning and makes it easier to update dependencies. So I am working in an crystallography project that needs wx-widgets 3.0.5 exactly. If it were in rust you could make this explicit and have cargo download it and compile it. In C++ I have to guess based on issues and zero documentation that I need to download this exact version. There is no enforced strict version management.
@ussuratoncachi
@ussuratoncachi 2 күн бұрын
Your Tic-tac-toe implementation, both in Python AND in C++, is astonishingly slow (10 tps and 100 tps). Even in Python, it should be at least 1k iterations per second. The solution to entire tic-tac-toe (all of its states) can be represented as a lookup table with size of a few kilobytes. It fits into L1 cache of any modern CPU in it's entirety. Because of this, in any compiled language, it should run **at least** at 5M - 40M iterations per second on a single core. I refuse to beleive, that anyone with "25 yrs of development experience", as stated in your channel bio, can have such little knowledge of performance and computers. You also did not put a link to any code, github repo, github profile or SN - not in this video, neither in the video prior, where you implemented tic-tac-toe AI in python. Python IS slow. However, what you are showing here is a huge skill issue, not Python issue.
@the_code_guy
@the_code_guy 2 күн бұрын
Yes i am aware that there are many ways to cheat at performance. The big thing about tic tac toe was implementing the minimax ai algorithm and not hard coded moves table. It's obvious that minimax is slow. It players every move to the end of the game each time. Ultimately though what is logically a heavy workload of calculations is way slower than in c++.
@roverkoech
@roverkoech Күн бұрын
Try mojo
@the_code_guy
@the_code_guy Күн бұрын
Thanks for the tip and for watching!
@gavintillman1884
@gavintillman1884 2 күн бұрын
Wonder how Rust would stack up here.
@vncstudio
@vncstudio 2 күн бұрын
Rust is as fast as C in some tests I did but I'm using C, Nim, and Python. No plans to use Rust.
@theairaccumulator7144
@theairaccumulator7144 2 күн бұрын
Rust literally uses LLVM as it's compiler backend, the same as Clang. If they're written in exactly the same way it would be exactly the speed as C/C++. Idiomatic Rust vs idiomatic C/C++ could show some interesting differences though
@the_code_guy
@the_code_guy 2 күн бұрын
Don't know enough about rust to have input unfortunately.
@Z4KIUS
@Z4KIUS 2 күн бұрын
Python is slow, hard to read, hard to write and hard to manage dependencies for a perfect language for people not related to IT
@federicobau8651
@federicobau8651 2 күн бұрын
Hard to read? 😂😂 hard to write? Mate if you tried to write on a language wuthout tried to learn it first and take a conclusion i dont think you can call your self a developer. Dependenies if you know what you are doing are a non-brain ... 2 min to install them if you know what you are doing, but you clearly are not 😂
@the_code_guy
@the_code_guy 2 күн бұрын
I have to agree with this comment. It is not natively hard to read or write. A developer can ruin the readability sure, but that easy in all languages
@Z4KIUS
@Z4KIUS 2 күн бұрын
@@the_code_guy it's very quirky and the lack of visible end of block tokens makes it much less scannable for actual human beings, I only use it as a last resort when the task I need to do is complex enough and there's a ready to use Python library while nothing else really can do that
@Siissioe123
@Siissioe123 2 күн бұрын
Python is overrated, Go is somewhat similar and really fast. Also python is terrible with large codebases. Not to mention the clashing/merging libraries. Python is never compiled into machine code, it gets executed by the Python Virtual Machine
@federicobau8651
@federicobau8651 2 күн бұрын
Python aint terrible in large code bases if you know what you are doing nope. You are comparing skill issues with a tool. Clashing / merging library? If you know how to prepare an environment chances to encounter issues with 3rd party packages is close to 0.
@the_code_guy
@the_code_guy 2 күн бұрын
I have to disagree that python is bad on large code basses. I have had no issues with it on large code bases. On the it gets executed by the python virtual machine yes, but this code still needs to make it to machine code to run.
@Siissioe123
@Siissioe123 Күн бұрын
@@the_code_guy I disagree
Зу-зу Күлпаш 2. Бригадир.
43:03
ASTANATV Movie
Рет қаралды 729 М.
«Кім тапқыр?» бағдарламасы
00:16
Balapan TV
Рет қаралды 293 М.
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 136 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 23 МЛН
Давайте поцарапаем iPhone 16 Pro Max!
0:57
Wylsacom
Рет қаралды 4,1 МЛН
Power Full Keypad Mobile So Beautiful
0:53
Nj Studio 24
Рет қаралды 752 М.
Самый дорогой iPHONE 16 PRO MAX #shorts
0:58
Арсений Петров
Рет қаралды 3,1 МЛН
Куда пропал Kodak?
1:01
MOTIVESSION
Рет қаралды 12 МЛН