Why is Python so Slow?

preview_player
Показать описание
So why is python such a slow programming language and how can we speed it up? In this video I'll be discussing the slow speed of the python language and why languages like Java, C and C++ can perform between 10x-200x faster.

◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python

◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

Tags:
- Tech With Tim
- Python Tutorials
- Why is Python so Slow
- Is Python Slow
- Python Speed

#Python #IsPythonToSlow
Рекомендации по теме
Комментарии
Автор

Hey guys just wanted to make clear that I believe I may have made some mistakes in the video! Some people that are clearly more educated on this specific topic and have left some polite comments to clear up any confusion. I'd like to apologize if I've misinformed anyone. I believe a majority of what I've said is correct but there may be have been a *more* correct answer to the question. It seems like the dynamic typing is an issue regarding speed but the more influential issue comes from the lack of a JIT compiler by default.

TechWithTim
Автор

Python in real life is slow also. Compared with other snakes.

BeachBoi
Автор

Python was not made to be fast...but to make developers fast...

prasangsinghal
Автор

The problem is that a scripting language has become so popular that we're holding it upto the expectations of compiled languages

RamkrishanYT
Автор

I graduated with a comp sci degree in 1974. I have programmed in assembler (several different), fortran, basic, C, mumps, cobol, pl/1, apl, lisp, java, C++, javascript, can't even remember them all. I met Donald Knuth and discussed structured programming with him. I was onto OO after reading the issue of Byte magazine that introduced smalltalk to the masses. I met Charles Moore, inventor of Forth, and worked with Jules of Jovial fame (well, maybe not fame). I supported the C++ run time library, cfront, and know LEX/YACC and how the internals of compilers and run times work.





For write only programs, python and similar are quick. If you are writing a corporate product with many parts and many people and care about performance, pleae give me static data typing. C++ and stl give you much of the goodness of python lists. I claim I can program in C++ or java almost as fast as python.


The speed of coding in python is due to the many magical diddles in the language, but that is a two edged sword. I say C++/Java is a little more verbose, but typing speed is not really an issue, and the quick writing is an inevitable tradeoff with clarity, at least to those who are not doing 10 hours a day with python. I would rather see spelled out code than a list comprehension, for instance.


Also, Java and C++ are pretty much what they started out as. Python is continually changing, multiple versions are very different, meaning learning and update time. Makes docs a nightmare of info about how it used to be and how it is now. Much worse than C++ and Java,



Also also, I have been using Kivy, and both kivy and python have documentation that was done quickly and often needs 2 or 3 times as many words, way too terse, seems like it never really does a top down discussion of things. Corporate libraries and languages I used had complete and relatively static documentation in known places. Python is all over the place.



There are tradeoffs, like clarity for brevity. As a silicon valley software architect, for quality, dependability, and clarity you have to pay a price, and I don't want to fly in an airplane whose software has dynamic typing. I know there are those who can read (and code in corporate settings gets read way more than written) python quickly, but for many, slower and less reliably correct.


If you are writing throwaway code, amusing yourself, or ???, okay python. For large projects with many modules, versions, programmers, maintainers, performance demands, etc, I would definitely choose C++ or Java.



Lastly, if you are writing software you expect to maintain and enhance over many years, at some point, you are going to have giant headaches over versions, do you stay with the 10 year old version, or massive convert? No good answer.

jt
Автор

The benefits of static typing are not limited to execution speed. It also results in a code base which is considerably easier to refactor years down the line.

JohnDavidDunlap
Автор

REEEE
Kinda wish you mentioned numpy for when you were referring to just raw speed for computing math. Numpy is much much more optimized than the base interpreter and is usually the answer to this type of issue.

Numpy is the reason why Python can be used for so many data analytics and machine learning applications.

harshitgupta
Автор

I've casually tried to learn coding many times, python has been the only language I have understood. Seems like a good place to start

DrumRoody
Автор

I mostly write in java, but python is spread everywhere. Learning python, makes you able to make webpages and apps, able to perform data science and machine learning, able to make a stand alone app for desktop. I think it is worth learning python.

Stl
Автор

Absolutely agree, every variable in python is by default an Object Class; in Java you can define variables to be primitive values, which helps it skip python's verification of datatype at runtime. Multithreading is also difficult in python while you can instruct Java to do it specifically when needed; my favourite language is still python for its simplicity and much friendlier user input structure in coding, so usually what I do is write up the code in python to run it, and if I need to reduce runtime for my software, I try to rewrite it in Java and hopefully achieve the same if not similar results.

spkim
Автор

Speed is a key factor to me.
That's why I chose Assembly.

brusch
Автор

"I'm learning as well."
Everybody likes a modest person.

chesshooligan
Автор

Dynamic typing isn't the biggest issue. Lacking a sufficiently powerful JIT is. JS and LuaJIT are bith dynamically typed and are orders of magnitude faster than Python. There are also other strategies like better opcode handling like in PHP's case.

AdolfExtra
Автор

Good video, Tim! As others have pointed out, nits can be picked over some wording choices, but I like the spirit of what you intended to do here. I have used many computer languages over the years: Basic (several flavors), Fortran, C, C++, Java, Assembly (Intel & Motorola), DOS, BASH, VMS, REXX, Matlab, RT-Works, ObjecTime, Avenue, and now Python. I am not a programming expert, or even a professional programmer, but my coding experience is fairly broad. The design goals of Python's creators focused on issues other than speed. They were more interested in usability and efficiency, as well as some very deep computer science crap ... I mean operability. For anyone who thinks Python was intended to be user-friendly, just try reading the official docs. However, the flexibility and robustness of this language are impressive. Still, it gives you plenty of rope to hang yourself; you can easily write poor code if you lack sufficient skill or discipline. That said, I think Python is a good first language for those who are willing to explore what it offers. It gives you plenty of tools to write good code, and perhaps more important, to develop good programming habits. A language like Visual Basic may be easier to learn, but the skills you can develop are limited, and you are likely to pick up some ugly habits. For more advanced programmers, Python offers a dynamic coding environment that allows you to achieve goals that are difficult to match in other languages. If you are willing to dig deep, you can write intentionally ugly code that will bypass typical limitations found elsewhere. You should not expect Python to perform well on code segments that involve serious number crunching or manual loop structures. But, there are advanced mechanisms available (in the base language) to help improve speed, such as ranges, iterators, maps, comprehensions, closures, etc. Like the 'sorted' built-in function, these code patterns leverage pre-optimized execution, behind the scenes. Without regard to the language/compiler used to build a particular Python implementation, these mechanisms represent a large manpower investment by dedicated people! If you learn how to use them well, they will help you write faster code. And, I think writing C (or Fortran) extensions is quite viable for extreme number crunching. If you like Java, use Jython in place of C-Python, and write Java extensions, instead. Just remember that powerful Python libraries, such as NumPy, are available, as well. If you need to take Fourier Transforms, for example, you might find that NumPy is faster than using a Java routine that you found on the Web -- it depends on array length, precision, etc. Ultimately, I agree with others that no one language will serve all your programming needs.

robbprof
Автор

Technically speaking, a python program would be slower than a similar c/c++ program by a constant factor, say 100X, not exponentially. Exponentials blow up really quickly

arjanbal
Автор

It's not just the case that Python uses dynamic typing but because its interpreter uses a stack-based virtual machine to execute python code instead of a register-based virtual machine like Lua uses and Lua is a very quick little scripting language.

GKNrd
Автор

bro if you can make a video on writing C extensions for python, that would be really helpful. Great vid btw, also what are your thoughts regarding Go ?

aakarshan
Автор

in my experience multiprocessing is simple enough if you set it up as here's your data, here's your code, come back to me when you're done. Setting it up that way is a lot easier for compute applications though

NovemberOrWhatever
Автор

7:07 "whenever you do this you need to shutup"

liamattard
Автор

You can speed up Python code quite substancially by using PyPy or Cython. Or by using LRE cache dictionary, that function doesnt have to re-calculate all over again in for/while loop

Sam-gdxp