Why is Python so Slow?

Поделиться
HTML-код
  • Опубликовано: 6 июл 2024
  • 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.
    ⭐️ Thanks to Kite for sponsoring this video! Download the best AI automcolplete for python programming for free: kite.com/download/?...
    ◾◾◾◾◾
    💻 Enroll in The Fundamentals of Programming w/ Python
    tech-with-tim.teachable.com/p...
    📸 Instagram: / tech_with_tim
    🌎 Website techwithtim.net
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-rusci. .
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    💵 One-Time Donations: www.paypal.com/donate/?token=...
    💰 Patreon: / techwithtim
    ◾◾◾◾◾◾
    ⚡ 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

Комментарии • 1,2 тыс.

  • @TechWithTim
    @TechWithTim  4 года назад +508

    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.

    • @hedleypanama
      @hedleypanama 4 года назад +2

      Golang is quite fast and it can be dinamically typed too using the assignment operator :=.
      Golang can be both interpreted or compiled!

    • @noelgomile3675
      @noelgomile3675 4 года назад +27

      @@hedleypanama The := assignment operator does not mean you are using dynamic typing, it means that you are letting Golang infer the type of the variable based on the data type that is on the right hand side of the operator. The variables will still not be allowed to have their data types changed however unless explicitly converted to a different data type. And Golang is a compiled language it is not both interpreted or compiled.

    • @mario123abc
      @mario123abc 4 года назад +3

      Tech With Tim Great video. One correction Java is not low level progamming. en.m.wikipedia.org/wiki/Low-level_programming_language

    • @kudoamv
      @kudoamv 4 года назад +4

      That mad guy in the corner in the of the room bashing keyboard laughs crazily as he types C and other assembly languages.
      .
      (cuz he a hacker x)

    • @bitbudsupport9925
      @bitbudsupport9925 4 года назад +4

      If I compile a python program and turn it to an exe.....will it run faster?

  • @BeachBoi1000
    @BeachBoi1000 3 года назад +1818

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

  • @RamkrishanYT
    @RamkrishanYT 4 года назад +1681

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

    • @platcrab4890
      @platcrab4890 4 года назад +31

      I mean is there much of a difference between a compiled language and a shell language? Python is still eventually run in assembly just like C or Java

    • @TricksterRad
      @TricksterRad 4 года назад +216

      @@platcrab4890 There's a difference between running interpreted bytecode (Python, Java, etc.) and actual machine code (C/C++). Also, please, do not confuse Machine Code (the thing your CPU runs) and Assembly (the thing you used to write programs in)
      Edit: Also, Java certainly does *not* compile into machine code.

    • @pencilcase8068
      @pencilcase8068 4 года назад +5

      The Zucc has spoken

    • @MJFAN666
      @MJFAN666 4 года назад +3

      @@TricksterRad how does Java run if not turned into assembly?

    • @TricksterRad
      @TricksterRad 4 года назад +104

      @@MJFAN666 Java gets turned into JVM bytecode. When you run a Java app, JVM executes that bytecode.
      If java were compiled into machine code, you wouldn't have to install JRE on every computer where you want to run java programs.

  • @prasangsinghal262
    @prasangsinghal262 4 года назад +2912

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

    • @TechWithTim
      @TechWithTim  4 года назад +292

      Ik!

    • @Lioneltunisianorevo
      @Lioneltunisianorevo 4 года назад +136

      Give that man a cookie 🍪

    • @zyrohnmng
      @zyrohnmng 4 года назад +17

      @@Lioneltunisianorevo But let that man know if you're in Europe!

    • @Lioneltunisianorevo
      @Lioneltunisianorevo 4 года назад +1

      @@zyrohnmng Tunisia :p but why ?

    • @RmDIrSudoSu
      @RmDIrSudoSu 4 года назад +69

      As is java.. Java is easier to program and faster to program, but far slower to run than C/C++.. It's the same for C# it's faster to code, but slower at runtime. That's why C++ is still a thing in 2019, because no other programming language can be as optimize as C/C++ (except the languages that also compile directly in assembly). But C/C++ is slower to code, way slower to code.. You need deep knowleadge of how your computer and language works to make it efficient at runtime. That's why Java and C# are everywhere and C++ is only used for application that required a lot of optimisation.

  • @JohnDavidDunlap
    @JohnDavidDunlap 2 года назад +131

    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.

    • @Jarrod_C
      @Jarrod_C 2 года назад +1

      how does it make it easier to refactor?

    • @JohnDavidDunlap
      @JohnDavidDunlap 2 года назад +8

      @@Jarrod_C Because there's more meta data embedded into the source code.

    • @rantalbott6963
      @rantalbott6963 2 года назад +11

      It also catches lots of mistakes that can be a bitch to find, like a spelling error in a variable name that creates a new variable at run time instead of an error message at compile time.
      It's "horses for courses": use something like Perl or Python for things that run interactively and don't hurt anyone if they fail, but a strict language for programming when failure is not an option.

    • @skaruts
      @skaruts 2 года назад +1

      This hasn't been my experience. Static typing always seems to involve a lot more thinking to refactor, plus a lot more writing.

    • @skaruts
      @skaruts 2 года назад

      @@rantalbott6963 that depends on the language design. But then, unless you're using notepad to write code, you're not gonna have many issues with mistyping variables. I've never had any difficult issues from it either way. That will result in some null variable error a few lines down, which will be enough to tell what's wrong pretty easily. (My experience is mostly with Lua, though, I haven't used that much python in the last 4-5 years.)
      However, Python does carry some stupid Murphy's Law traps. For example: *x = 10* always defaults to a local *new variable,* and since it's so easy to forget to preface a function with *global x,* you can (and will) find yourself wasting hours on a weird problem caused by that. In Lua this is never a problem; as long as you know to avoid using globals, you're always in direct control of scope.

  • @harshitgupta6856
    @harshitgupta6856 4 года назад +359

    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.

    • @jwhite1202
      @jwhite1202 4 года назад +34

      Harshit Gupta Agreed. Machine Learning is definitely Pythons sweet spot. I love Java, but none of Java’s data structures comes close to pandas and data frames. Those alone makes stats and ML doable without a Ph.D.

    • @ShadowaOsu
      @ShadowaOsu 4 года назад +61

      Numpy is fast, I wonder what's the reason behind it omegalul.
      Could it be, because, *ehem*, heavy parts of it are coded in coded in C?

    • @maxclifford937
      @maxclifford937 4 года назад +43

      @@ShadowaOsu also the most the machine learning bits in python are just wrappers around c/c++ code

    • @ShadowaOsu
      @ShadowaOsu 4 года назад +1

      @@maxclifford937 yea exactly

    • @mennoltvanalten7260
      @mennoltvanalten7260 4 года назад +28

      > Could it be, because, *ehem*, heavy parts of it are coded in coded in C?
      Yes, and so it would have been a great example as an extension someone has already written.

  • @DrumRoody
    @DrumRoody 4 года назад +477

    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

    • @ajricherson1099
      @ajricherson1099 4 года назад +4

      Can I ask which languages you tried to learn?

    • @DrumRoody
      @DrumRoody 4 года назад +20

      @@ajricherson1099 brainfuck. Joke. It was C or one of its variants

    • @ajricherson1099
      @ajricherson1099 4 года назад +65

      @@DrumRoody You are really comparing two ends of the spectrum then. C is pretty low level language, and Python is one of the higher level programming languages. Just something to think about.
      If you do want to learn another language, I would recommend something like Java, C#, or perhaps JS if youre interested in web dev

    • @lincolnsand5127
      @lincolnsand5127 4 года назад +25

      @@DrumRoody I use C, C++, & Rust. I definitely find them much more expressive & powerful than python. Also. Brainfuck can be used as a test output for compilers. Brainfuck is essentially simplified assembly language.

    • @incognitojon902
      @incognitojon902 4 года назад +14

      Lincoln Sand this has to be a joke brainfuck was created to fuck ur brain it’s not useful for anything

  • @jt95124
    @jt95124 4 года назад +157

    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.

    • @sumodmadhavan
      @sumodmadhavan 4 года назад +1

      jt95124 What is your observation about ADA. Is it still active? Will you choose ADA over C++/C why? Why didn’t ADA fly?

    • @jt95124
      @jt95124 4 года назад +4

      @@sumodmadhavan ada was trying to be c++ but with async multithreading built in. It was developed and pushed by Dept of defense as solution to their issues. C++ does the same thing and grew from the C culture, so had community and momentum.

    • @jt95124
      @jt95124 4 года назад +3

      @@sumodmadhavan languages succeed by large community, Adam has none, so no open source, no tools, no programmers

    • @Calvin_M.
      @Calvin_M. 4 года назад

      I'm studying C++ and Python languages right now in my univeristy, which language would you recommend me to develop also and should I?

    • @masheroz
      @masheroz 4 года назад +1

      What about Fortran?

  • @chesshooligan1282
    @chesshooligan1282 4 года назад +61

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

  • @cx3268
    @cx3268 4 года назад +432

    Interpreted VS compiled

    • @TechWithTim
      @TechWithTim  4 года назад +65

      Python is still compiled! Just differently than other languages.

    • @tobychadderton4209
      @tobychadderton4209 4 года назад +7

      @@TechWithTim only when you use bytecode right?
      Python is interpreted when you run a .py script

    • @TechWithTim
      @TechWithTim  4 года назад +37

      it’s compiled to .pyc then *interpreted as byte code.

    • @TricksterRad
      @TricksterRad 4 года назад +5

      @@tobychadderton4209 Python is compiled before running into __pycache__ directories.

    • @AsirIset
      @AsirIset 4 года назад +4

      But isn't Java interpreted as well?

  • @G33KN3rd
    @G33KN3rd 4 года назад +10

    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.

  • @aakarshan4644
    @aakarshan4644 4 года назад +29

    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 ?

  • @spkim0921
    @spkim0921 Год назад +14

    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.

  • @NovemberOrWhatever
    @NovemberOrWhatever 4 года назад +24

    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

  • @Adolf1Extra
    @Adolf1Extra 4 года назад +167

    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.

    • @BrandonClapp
      @BrandonClapp 3 года назад +6

      I was thinking this exact thing while I was watching this video.

    • @kazaamjt1901
      @kazaamjt1901 3 года назад +4

      I mean, python does spend a good 90%+ of it's time doing type checking. A better jit compiler could help, but if you really need speed in python, replacing critical parts with C or Cython will give far superior performance over any jit.

    • @DWVoid0321
      @DWVoid0321 3 года назад +2

      I remember that Graalvm can run python3 and boasts great performance. Haven't got a load to try that but maybe a solution?

    • @chudchadanstud
      @chudchadanstud 2 года назад

      No. It's part of the problem. Dynamically typed languages are slow, even auto in C++ is slow. Python has a lot of things that work together to make it slow. If you care about real-time don't use Python.

    • @nourios6991
      @nourios6991 2 года назад +8

      @@chudchadanstud how is auto slow in c++ if the type is evaluated at compile time?

  • @Stl71
    @Stl71 Год назад +17

    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.

  • @laikbl
    @laikbl 4 года назад +8

    Very informative and important at the same time, thx!

  • @brusch1553
    @brusch1553 3 года назад +72

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

    • @zodiaq7186
      @zodiaq7186 2 года назад +1

      what?

    • @78anurag
      @78anurag 2 года назад +3

      Tf

    • @gavinthecrafter
      @gavinthecrafter 2 года назад +14

      I'm assuming you're joking, but unless you're trying to run your program on a computer from 1989, you probably don't need to go _that_ low level. C and C++ should be plenty fast enough.

    • @brusch1553
      @brusch1553 2 года назад +6

      @@gavinthecrafter your assumption was right

    • @yourboiivan
      @yourboiivan 2 года назад +3

      Hats off

  • @tom_stephen
    @tom_stephen Год назад

    Out of curiosity, does pre-stating type of variable (varname: int, for example) make Python code more effective?
    And, one more question, would it be possible for language to use both types of variables, so you decide whether you want this part of code be more effective, and the other more dynamic?
    I have the idea of creating my own language mixing Python simpleness with Java/C effectiveness, but as I'm currently too newbie for it, I'm curious whether this is even possible.

  • @techno-sachin165
    @techno-sachin165 4 года назад

    Tim!!!! I can't Install Kite!!! It says Tensorflow requires CPU instruction set AVX which is not mine.. :-(

  • @FabledNarrative
    @FabledNarrative 4 года назад +23

    Keep up the great work, man!
    Videos like these seem simple, but in the long run,
    it will show case how much of a professional and teacher you are.
    :D

  • @arjanbal3972
    @arjanbal3972 3 года назад +44

    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

    • @rinrin4711
      @rinrin4711 3 года назад +21

      Actually, no. There cannot exist a functionally-desribed correlation between Python and C speed. Even if you write 100 pairs of absolutely semantically identical pieces of code in Python and C that cover different aspects of programming and measure the execution speed difference for each pair. You will not be able to drive any meaningfull corellation between those two languages outside of Python being generally much slower. Why? For many reasons. One of them is compiler optimisations for C. For example, if you write a simple cycle that adds 5 to variable y 1000 times, in C this code will be compiled to just "y = y + 5000", while Python will execute all 1000 loop iterations effectively executing at least 1000 slower, but if there were only 10 loop iterations then the code would be only 10 times slower. However these 1000 times and 10 time are also not representative, since integers are absolutely different things in those languages and different operations might(will) have different speed ratios.
      There are many other reasons, but I think you got an idea)

    • @CallousCoder
      @CallousCoder Год назад

      Actually in same cases it can be far more than exponentially faster than Python.
      Python has no contextually knowledge of types and therefore of optimization.
      I have optimized a piece of Python code to run 100+ times faster by changing I % 2== 0 into I & 1 == 1 and changing division of multiples of two by shifting right!
      These are far more than exponentially faster situations, because a division on an x64 takes 45-93 cycles a shift and bit wise operation 1 cycle!
      Changing the run speed of that back batch processor from running 6-7 minutes to 33 seconds. In total since these operations were the crippling factor.
      A compiler does these sorts of optimizations for you because it has context. And when I tell a compiler to optimize for speed, it can (and will) un roll loops avoiding many of 100s or even 1000s compare and branch statements. Having a million of the instruction instructions in a row compared to 1 or those and a million compared and branch shorts saved at least 8 cycles per time so 8.000.000 cycles.
      But of course every problem is unique so it would not scale quadratically on all factors but most often a C/C++ at least teams 4 to 100 times as fast! And I some cases but 1000s of times.
      This is why I advocate that every programmer at least have 1 semester of experience in assembly. Because then you know to avoid those deadly pitfalls.

  • @abeltan2168
    @abeltan2168 4 года назад

    Hi Tim,
    Say i write a code in kivy. Its slow in python. After i compile it to android will it speed up?
    Thanks

  • @benjien2007
    @benjien2007 4 года назад

    I have a project in mind and I need some advice, will you be able to assist me?

  • @liamattard3899
    @liamattard3899 4 года назад +94

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

    • @PwnUrBadCock
      @PwnUrBadCock 4 года назад +4

      I was looking for this comment

    • @disk38
      @disk38 4 года назад +1

      lmao that got me

  • @robbprof111
    @robbprof111 3 года назад +20

    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.

    • @StrangeIndeed
      @StrangeIndeed 3 года назад +1

      top notch comment c:

    • @uguree
      @uguree 3 года назад

      Well very nice comment but compressions don't make your code faster just tidier!
      Cheers

    • @ajflink
      @ajflink Год назад

      I have made essentially a curse word check in Python that checks for curses being used in a word, is simply a curse word, or composed of multiple and/or repeating curse words as well as having different rules for strings after a certain length. It can do a maximum of very roughly over 2 million checks before determining if a curse word is present in less than 1 second. I have recreated the Python code in C to discover that the speed is essentially the same and could not improve the speed in C any further.
      In general, Python is slower; however, when creating solutions and algorithms only possible in Python, it quickly becomes one of the fastest.

    • @dgh25
      @dgh25 Год назад

      👏

    • @robbprof111
      @robbprof111 Год назад

      @@uguree Perhaps. Cheers!

  • @arbazkhan8320
    @arbazkhan8320 4 года назад +5

    Thanks for explaining it in a simple way...👍

  • @CHITUS
    @CHITUS 2 года назад +3

    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

  • @ChaosArtist
    @ChaosArtist 2 года назад +3

    I use Python a lot in my job, thanks for your explanation on why Python is slower than lower-level languages like Java and C.

  • @ruslankudriachenko5673
    @ruslankudriachenko5673 3 года назад +13

    I am not sure about the statement: the python is slow because its dynamic. Why? Lua.
    I am sure there is more to that. I am not an expert in python, but I think it's close enough.

  • @rohitjon4512
    @rohitjon4512 3 года назад +2

    Tim, what do you think about a language like Julia which is easy to write and at the same time has fast execution?

  • @15chris45chris
    @15chris45chris Год назад

    Could we just as well use C# or C++ to import as an extension? Or does it have to be C specifically?

  • @pablomartinezazcona8450
    @pablomartinezazcona8450 3 года назад +3

    I am not an expert on this topic but I usually do heavy calculations in python and there's a module called Numba which has most of numpy's functions built in and it allows you to run some functions in python much faster, and even use parallel computation. It has allowed me to speed up my code a lot.

  • @dylanharding5720
    @dylanharding5720 3 года назад +2

    The main speed issue comes from the lack of a jit compiler. Pypy includes one, and, especially with long running scripts, can see as much as 6 times the performance increase. (note that it can be slower at times, especially with short running scripts)

  • @InternetMadeCoder
    @InternetMadeCoder 2 года назад

    Such a great explanation Tim!

  • @ninjacncrazy6910
    @ninjacncrazy6910 2 года назад

    I had a question does you're pc performance create a difference to the python runtime?

  • @CyberQuickYT
    @CyberQuickYT 3 года назад +29

    thumbnail is misleading, Java isn't 3rd fastest language by any means.
    There are faster/more efficient languages, usually those which get compiled into native code, not into vm code.

    • @atomfusion231
      @atomfusion231 3 года назад +10

      It’s also misinformative as well. Python is an interpreter while C,C++ and java are all compilers, which provides a massive difference in performance. It’s why I dislike these comparison videos, as it’s comparing different types of how a language is run on something like speed. Compilers are usually faster than interpreters.

    • @programmer4047
      @programmer4047 3 года назад +3

      Even C isnt the fastest language, assembly and few other languages are much faster than C

    • @embeddedbastler6406
      @embeddedbastler6406 3 года назад +8

      @@atomfusion231 Java compiles to bytecode, not to machine code. This means at runtime there is still a interpretation.

    • @embeddedbastler6406
      @embeddedbastler6406 3 года назад +7

      @@programmer4047 Since both Assembly and C do compile to machine code, you can't simply say one language is faster than the other. It depends on optimization and the quality of the code.

    • @CyberQuickYT
      @CyberQuickYT 3 года назад +2

      @@programmer4047 I have to disagree with you. C compilers are very optimized, so the generated machine code is often more efficient than if you would write assembly by hand.

  • @stifenjans4342
    @stifenjans4342 4 года назад

    @techwithtim, does octave language at same case(madlab)? i don't take research about metleb

  • @HABIBMUHD92
    @HABIBMUHD92 4 года назад

    Informative as always thank you!

  • @md.nasiruddinprotul1315
    @md.nasiruddinprotul1315 4 года назад +7

    If I have to write code in C to optimize, then why would I import it in Python and then run it. I can just run it as a C program with the C compiler.

    • @thedoublehelix5661
      @thedoublehelix5661 3 года назад +1

      Tell that to tensorflow

    • @onebacon_
      @onebacon_ 3 года назад +1

      If you already have a complex program, but one function is very slow. You can outsource that to the c compiler to optimize. This way you can keep the simplicity and elegance of python code while providing speed on complex requests.

    • @HermanWillems
      @HermanWillems 3 года назад

      Python is a composing language, a front-end language for gluing together modules like you are composing a solution. That's where python shines.

  • @atharva1237
    @atharva1237 4 года назад +3

    Can u make a video on how to use C as an extension for python? Love your video as always.

  • @MK-fw5bt
    @MK-fw5bt 3 года назад

    Thank you for Sharing, Tim!

  • @nagendravarma8495
    @nagendravarma8495 4 года назад

    But u haven't mentioned.. What kinda libraries we should import?

  • @manojpawarsj3329
    @manojpawarsj3329 4 года назад +40

    How about cython?

  • @igorthelight
    @igorthelight 4 года назад +8

    How to make Java fast - use JIT compiler with "Server" preset
    How to make Python fast - use JIT compiler (PyPy) or compile your libraries to C and import them in your project (CPython). Second is more difficult and clashes with Python idea to be elegant and simple.

  • @DiasDenny
    @DiasDenny 4 года назад +1

    Can you plz explain how would I write c extension code in python

  • @MhmdK0030
    @MhmdK0030 3 года назад +1

    Great work Tim!! Keep it up 🌷🌹

  • @atrumluminarium
    @atrumluminarium 4 года назад +13

    With regards to making "native python" faster, Numba is amazing. It's effectively just a decorator over native python and the acceleration on numerical tasks is comparable to C/Fortran with the simplicity of python.
    It also can interact with numpy for those wondering but at that point just use cython and import C headers directly since you're already deviating so much from native

    • @stdklr
      @stdklr 2 года назад +3

      Very important answer! You don't need to write C to make python faster. Let numba do it for you. It's converting your python code to C quite efficiently. You can keep your core code in python with all the convenience python is providing and just decorate the number crunching function that gives you a headache with numba. If it includes a prallelizable for loop you can just use numba's "prange" to even parallelize code.

    • @brianmcconnel640
      @brianmcconnel640 2 года назад

      This is the best comment on this video. There are reasons for why python was developed the way it was and why it is so popular. It feel like this video does not do the topic justice, and misrepresents the power of python. The better way to think of python is a general purpose scripting language for calling optimized libraries. If you are using it any other way you will be disappointed.

  • @pushpajitbiswas3752
    @pushpajitbiswas3752 4 года назад +49

    Really important video for python interview question, nicely explained man 👍

  • @alek4498
    @alek4498 4 года назад +2

    Sorry for noob question, but does that mean JavaScript runs into the same issue too since (I think) it is also dynamically/weakly typed?

    • @Adolf1Extra
      @Adolf1Extra 4 года назад +2

      No, the powerful JIT compilers major engine vendors use remedy that aspect. JS in many aspects is faster than LuaJIT even.

    • @hexhackbangla8368
      @hexhackbangla8368 4 года назад

      Js does not works like python, python depend on precompiled executable module, while js is run like a script in an script engine. So that gives js slightly more speed for realtime compilation engine.But if you wanna use js for desktop application speed will be worse than python.

    • @radityoperwianto1339
      @radityoperwianto1339 4 года назад +1

      Yes, JS engine runtime is slow..

  • @24mrdanny
    @24mrdanny 4 года назад +2

    Does anyone know if when I use static type checking in python, do some of the slowness issues he mentioned go away?
    Python Static Types: medium.com/@ageitgey/learn-how-to-use-static-type-checking-in-python-3-6-in-10-minutes-12c86d72677b

    • @pavlg3944
      @pavlg3944 4 года назад

      Because static keyword locks the object to the memory so when its context or class is destroyed, it's done & you cannot use it w/o passing the compiler back to the line of the declaration of that variable or object ....so it helps in terms of performance and memory but you cannot use this in dynamic cases because if you destroy the thread of class or context having that variable & use that variable in a context you will get a NullPointerException or IllegalStateException & by the way static makes the object creatable only at the runtime of the context only one-time after that you cannot recreate it ...you will have to reRun the context or the application

  • @KayOScode
    @KayOScode 3 года назад +6

    So basically: how you make python faster is just using c. Glad we can agree on that

  • @FeedFall8
    @FeedFall8 4 года назад +6

    can you do a tutorial on using cython to convert python programs to c\c++?

  • @justinlee3453
    @justinlee3453 3 года назад

    super clear explanation and answers some of my problems I previously thought of

  • @sobreaver
    @sobreaver 4 года назад

    But how is it, that with this new program I've been using lately, the late version 2.8 of Blender, I can't see any difference in speed, if anything, it loads ultra fast and does all if not almost a better job than some other 3D packages, I'm really not trying to debate the worth or performance of Blender, I'm really just curious about the programming language. So how is it that I don't 'feel' this slowness of Python ? Is it just more visible in web development rather than desktop applications ?

  • @SimGunther
    @SimGunther 4 года назад +102

    UNIX: Everything's a file
    Python: Everything's an object, even when it doesn't need to be with unnecessarily high amount of levels in our hierarchies
    Smalltalk: Everything's an object, we just need reserved protocols and pointers to support our speedy tape measure despite the fact that we don't have an easy way to deploy our code
    C: Everything is a pointer, sometimes to functions, so be wary or else you get a segmentation fault for free

    • @__jan
      @__jan 4 года назад +3

      In short, C is far superior to anything when you implement and use smart pointers.

    • @ShadersRS666
      @ShadersRS666 4 года назад +3

      @@__jan What is a smart pointer in C?

    • @ShadersRS666
      @ShadersRS666 4 года назад

      @@__jan Nothing exists all that pointers relies in memory and usage in typecasting in every single type that you see in pointers just goes through a specific memory address then you can disassemble in x86 where its going to head to in the offset relied in memory when it points you can make it point to another type

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 4 года назад +15

      Smart Pointers only exist in C++, not in C, as smart pointers heavily rely on destructor methods that are called after an object has gone out of scope and is to be deleted. C doesn't have objects, hence it doesn't have destructors either.

    • @OfficialRichardNixon
      @OfficialRichardNixon 4 года назад

      Vivek Yadav worst case make malloc/calloc/realloc/free wrappers maintaining a global array of void pointers thats freed via atexit. It’s janky but works if watch for abort

  • @codewithwasif3517
    @codewithwasif3517 4 года назад +8

    Love the way you explain things 💞

  • @blindshellvideos
    @blindshellvideos 3 года назад

    Do the external C functions use more than 1 thread?

  • @planktonfun1
    @planktonfun1 4 года назад

    That made sense, thanks!

  • @MegaToyy
    @MegaToyy 4 года назад +22

    Python is a great PL for certain purposes. Imagine you need to walk to your barbershop one block away from home. Well you could . time your speed ,call a helicopter for that matter, and wait an hour for it to get to your house. Then find a place to land and so on.. Or you could simply use your Dynamic legs and put them into work.

    • @amirmousawi9156
      @amirmousawi9156 4 года назад

      женя except when speed is necessary

    • @matiasrisso5917
      @matiasrisso5917 4 года назад +3

      @@amirmousawi9156 Well, he specifically gave a case when you don't. So what's your point?

    • @amirmousawi9156
      @amirmousawi9156 4 года назад

      I dont need to. It is obvious that python runtime is slow compare to languages such as c and c++.

    • @amirmousawi9156
      @amirmousawi9156 4 года назад

      @@matiasrisso5917 I dont need to. It is obvious that python runtime is slow compare to languages such as c and c++. So when speed is important python is not a good choice.

    • @Mallu_drink_cow_piss
      @Mallu_drink_cow_piss 2 года назад

      stupid logic 😂

  • @norpriest521
    @norpriest521 3 года назад +4

    But I'm Data Engineer, not Software Developer.
    So I still need to use Python for the most part.
    So I guess as a Data Engineer, this is not gonna affect me, right?
    Data Engineer only uses Python to get their job done.
    No need to adapt in soon future?

  • @DavidKing-wk1ws
    @DavidKing-wk1ws 4 года назад

    Why not take the source to flow chart and recode in assembly?

  • @adriftinsleepwakefulness7039
    @adriftinsleepwakefulness7039 4 года назад

    Based on what you are mentioning, how does python divide tasks for GPUs using tensorflow? Python can call c++ code and achieve Parallel Processing? What happens to python with transactional memory?

    • @CallousCoder
      @CallousCoder Год назад

      The NVIDIA (CUDA toolkit) actually demands that copy your data set into its memory using the cudaMAlloc() to allocate that memory and a cudaMemcpy() then you tell the api how many threads and grid you want to work on that data. At that moment when the CUDA kernel is started it runs in parallels your program is just there or load the data and start it and that can be single threaded - and your applications has no more knowledge than to wait for the CUDA kernel to finish its call.
      You then have to copy back that memory from the GPU and in some cases you have each grid manage its own memory section for atomic reasons and consolidate those results.
      So your interpreted doesn’t gets taxed with the concurrency and memory management that’s simply offloaded to the GPU and you basically wait for a “run” instruction to end. So for Python (or C++ in my case) the setup and run code is very much single threaded.

  • @thanatosor
    @thanatosor 4 года назад +17

    If you can write fast code with slow language and have fun then you still can write faster code with fast language

  • @yuvalmusali2492
    @yuvalmusali2492 4 года назад +3

    That's right, but you have to remember that you can still define the type of variables in Python, and I actually use it a lot, for example:
    var: int
    That way Python know to inform you that you can't use string functions and methods on this variable, while you CAN use int functions and methods, or that you can or cannot send a certain parameter to a function according to its type.

  • @velfad
    @velfad 3 года назад +1

    Any language requires special API to work with multi-threading, such as locks for shared objects. However certain compilers for statically typed languages might be advanced enough to do it automatically for some algorithms. It's just nobody bothered to implement this in Python so you have to do it all manually...

  • @angelfranciscotorresnovero4168

    Can I also import C++ code in python or only C code?

  • @justinlee4572
    @justinlee4572 3 года назад +9

    important to note: For most io bound loads (like running a web server), having n threads does not directly translate to n times performance. Also, single threaded asyncio based webservers frameworks like uvicorn/ node are often surprisingly fast.

    • @marcossidoruk8033
      @marcossidoruk8033 11 месяцев назад

      If you are IO bound 95% of the time and then you get a sudden spike in things to do that will still translate to a sudden lag spike once in a while and thus bad user experience.
      To this one should add that latencies add, even if the work your program does is 2x faster than the IO that still represents 33% of the latency time in your program, wich is quite significant.
      "IO slow therefore performance doesn't matter" is a terrible excuse 90% of the time, if you are doing something utterly trivial it might be a good excuse but as long as your program is actually doing something half interesting performance is important, perhaps not triple A video game kind of performance but in some way or form you should care about performance.

  • @michealhall7776
    @michealhall7776 4 года назад +5

    Tim can you make a video about importing c code into python. What about c++?

    • @MSneberger
      @MSneberger 4 года назад +1

      Why not just write C/C++ then?

    • @madhulikamadhu51
      @madhulikamadhu51 3 года назад +1

      If you took your pain to write in c
      Let your prograam run in a 200 times faster language, don't convert to python

  • @codingbrother7237
    @codingbrother7237 3 года назад

    I am a beginner here. what do you mean of speed in programming languages?

  • @Sunwarul
    @Sunwarul 4 года назад +2

    Thank you, brother. make a similar on NodeJS and PHP7 please.

  • @Chertograad
    @Chertograad Год назад +5

    Then why is JavaScript so incredibly fast (especially comparing to Python) even though it is also dynamically typed?
    I'm not counter-argumenting. Just trying to understand...

    • @frostyflame4008
      @frostyflame4008 Год назад +5

      pretty sure its all because JavaScript compiles the source code before the program starts, while Python does it one by one line

    • @thefoolishgmodcube2644
      @thefoolishgmodcube2644 Год назад +1

      Same for Lua. It's also dynamically typed but runs just as fast as a C program according to Linux's time command

    • @houstonfirefox
      @houstonfirefox Год назад

      JavaScript isn't a real language IMHO 🤣

  • @TobiPlayHD
    @TobiPlayHD 4 года назад +21

    Writing main code in Python and importing Fortran/C algorithms is the way to go for me, most if the time at least. For most people speed really does not matter - if your code is written poorly in C there is no benefit to using it.

  • @adogpersonblog4176
    @adogpersonblog4176 3 года назад

    does it affect after the python file is made into a .exe file? is the exe file is slow too?

  • @WiredMartian
    @WiredMartian 3 года назад

    Finally, Thank you 🙏🏽

  • @nicop175
    @nicop175 4 года назад +3

    Hey Tim, can you do a video building a C extension? Thanks, love your channel! ♥️

  • @olegkorsunskyi7007
    @olegkorsunskyi7007 4 года назад +51

    Tell about the different versions of Python such as Pypy, IronPython, Jython and so on.

    • @user-ob5hj5vn8c
      @user-ob5hj5vn8c 4 года назад +7

      Oleg Korsunskyi PyPy is fucking fast. Insanely fast. IronPython and Jython I think just allows c# and Java libraries

    • @xeome5596
      @xeome5596 4 года назад +1

      @@user-ob5hj5vn8c still not fast as c++ or c or luajit

    • @user-ob5hj5vn8c
      @user-ob5hj5vn8c 4 года назад +6

      ​@@xeome5596 True, although compared to regular python it is fast as helllllll

    • @jodazague8333
      @jodazague8333 4 года назад +1

      Isn't IronPy dead?

  • @gwenaeloppitz3972
    @gwenaeloppitz3972 3 года назад

    Really interesting man thanks

  • @siyathokozankosi5469
    @siyathokozankosi5469 4 года назад

    Tech With Tim, I'm struggling to find a proper programming language for algorithmic trading I don't know whether I should use Python, Java or C# for that matter can you please make a video, or comment advising on what programming language is suitable for what[In algorithmic trading of course], because I'm new to algo Trade and I kind of don't know what goes where.

    • @DenisOrlov
      @DenisOrlov 4 года назад

      Good comparison of languages and their pros/cons in relation to algo trading rokpovsic.com/which-language-to-use-with-tws-api-interactive-brokers-api.html

    • @josephbrandenburg4373
      @josephbrandenburg4373 4 года назад

      Make sure to look into NumPy and SciPy. These are some excellent math libraries.

  • @arbazkhan8320
    @arbazkhan8320 4 года назад +18

    Can you make a video of how we can import a c progam in Python as an extension??

    • @TheTWYChannel
      @TheTWYChannel 4 года назад +1

      Bhai kya bol raha ho

    • @Rajat-Sharma1
      @Rajat-Sharma1 4 года назад +1

      😱

    • @omparikh4426
      @omparikh4426 4 года назад +1

      🤣

    • @epsilonator
      @epsilonator 4 года назад +2

      He's not kidding. It's possible

    • @omparikh4426
      @omparikh4426 4 года назад +2

      @@epsilonator it's possible but not the way he describes. First you need to convert to bytecode to implement that

  • @doldol1
    @doldol1 3 года назад +8

    "python in an extremely slow programming language", you're confusing language with implementation there. In this case you're talking about CPython, the reference implementation of Python

    • @chudchadanstud
      @chudchadanstud 2 года назад +1

      CPython is not python. It's C. You're just converting your code to C and compiling.

  • @kubakakauko
    @kubakakauko 4 года назад

    Anything like kite but for C# ?

  • @juanandrade2998
    @juanandrade2998 3 года назад +1

    I'm I the only one that devolps tools for automatic generic typecast in Java?
    At first, it is slow, but once you have whats necessary it basically stops being Java, and it stills as efficient.

  • @jimihenrik11
    @jimihenrik11 4 года назад +3

    This is the first time I ever heard someone say java was fast. I usually get to hear stuff like "slow languages like java are so inferior to faster languages like haskell".

    • @lincolnsand5127
      @lincolnsand5127 4 года назад +1

      Haskell is not a fast language. Neither is java. Haskell has extremely strong typing, but is very high level, it also has a gc. Its gc is better than java's. Java is slow because it uses the jvm & a gc. C & Rust would be good examples of fast languages.

    • @chaddaifouche536
      @chaddaifouche536 4 года назад

      @@lincolnsand5127 In so far as we compare the couple "Language + standard compiler/interpreter", Haskell with GHC is definitely in the fast category. Of course what often makes the difference is the algorithms you use and idioms in your language can influence you to write slow code, such is the case with Haskell if you use the default lists and strings as a panacea (it is very easy to use better data structures without changing your code much thanks to type class but beginners are not always aware of that).
      On the other hand I would also place Java in the fast category, comparable to Haskell.
      The absolute best languages to write performance critical code are still C, C++, Rust or Fortran (eventually with some Asm) but you very rarely need this kind of performance in general programming and can often make do with fast high-level languages like Java, C#, Haskell, OCaml and so on. C and Fortran should probably be a last resort if you really need the performance, they're much too low level. C++ and Rust are reasonably high-level and Rust even provides a lot of safety compared to C/C++ but they're still more painful to write in than a higher level language.

    • @lincolnsand5127
      @lincolnsand5127 4 года назад

      @@chaddaifouche536 I'll tackle this in pieces. So. For the first part, Haskell is just a bit faster than java but nowhere near C/C++. Haskell is memory efficient and has the best gc I've ever seen. As for what fast is, I think Haskell and Java are slow because I mainly use C++ & Rust. So to me, these languages are slow. If you're using a snail language like Ruby or python, then Java is probably "fast." As for the last part, I somewhat disagree. I regularly use Rust even when I'm not doing performance critical operations because its abstractions and type systems are better than most mainstream high level languages that I've seen. I also think that pointers and consistent object lifetimes are very useful for code design and modeling how code should behave and neither of these are possible in high level languages (usually). Lastly, while C++ *can* be a pain sometimes, I think Rust is nicer to write code in than most high level languages. Also. I agree that Fortran and assembly are painful and should only be used when needed.

  • @nopens
    @nopens 4 года назад +5

    Good video. Thank you. Python is fast *enough*, but as with anything in programming, you gotta use specific tools for specific task when you have to achieve best results. Im sure some time in the future (maybe python5?) will catch up in speeds.

    • @supremedeity9003
      @supremedeity9003 4 года назад +2

      well the problem is not a problem in code. the actual thing is just python is interpreted and c++ etc are compiled.

  • @AtomkeySinclair
    @AtomkeySinclair 4 года назад +2

    Great content here. Thx. It think py gained popularity from the Maker folks - stem, rpi, arduino, iot... etc. And to make things worse, the desire for intermediate understanding of deep learning. Think scikit and Tensorflow. Which is crazy since that is mostly linear algebra, matrix math - and intensive list handling. But py makes the approach easy to handle especially for type conversions and containers. So the simplicity of py made coding it so attractive that folks got spoiled with it. Pre-existing cookie-cutter copy-past code and libs for interfacing with hardware and server services made it super easy. See github for copious examples. Attempting to move into C from that background will prove very frustrating. The whole idea that "I have to allocate and free memory for a variable?" mentality is just the beginning of it. And to be honest, some introductions in newer C++ standards are re-creating that lax attitude. Smart, self-maintaining classes like deque, array, and vector remove the responsibility from the programmer to know the actual algorithm/implementation by hiding it in the so-loved obscurity of object abstraction. Sometimes, I think, over encapsulation/abstraction will end up shooting you in the foot. It might just be that you could double the speed of a code section by doing it yourself. Class and template expectations are often large in the final design. Often simple is far better.

  • @Luix
    @Luix 3 года назад +3

    C++, golang, rust. Or use wrappers like in ML.

  • @sidneywinter8952
    @sidneywinter8952 3 года назад +6

    An interpreter that runs slow.,, That ring a bell! OMG, it reminds me of the old BASICA programming languag the 1980's and MS-DOS. Python is the BASIC!

    • @fatfurry
      @fatfurry 3 года назад +1

      Yes!

    • @simpletongeek
      @simpletongeek 3 года назад

      Old Basica? That was never popular. I'm surprised you mentioned that one. I think Atari Basic holds the prize for being the slowest of them all. It has a relatively powerful set of commands, but they have to make a lot of sacrifices to fit them into 8K. Later Basics for Atari broke the 8K limit and thus run much faster.

    • @sidneywinter8952
      @sidneywinter8952 3 года назад

      @@simpletongeek I'm comptemplating to either learn a new language like Python, Java, or the like or just keep using some of my older compilers.

    • @simpletongeek
      @simpletongeek 3 года назад

      @@sidneywinter8952 why would you want to learn a new language? For backend server side development, python is the wrong language to learn. For front end development, that's HTML5, CSS, Javascript.
      Java is good for generic usage, so you may want to learn that. I prefer Processing, though. It compiles to Java, and in fact, you will need Java for the really advanced usage of it. Processing is the gateway to Java and Javascript (via P5.js)
      If it's for personal use, then anything is fine. I'm currently finding out that Bash is rather powerful all by itself, and that assuming you don't need GUI, it can handle a lot of the old style textual interface programs.
      My preference is actually Basic and C, but Perl/Python/Ruby are useful. Just pick one. HTH.

    • @sidneywinter8952
      @sidneywinter8952 3 года назад

      @@simpletongeek I'm retiring next year (62) and I thought about upgrading to the new "languages". I took a course (Java) at a local community college and later saw some tutorials on the languages, so I decided to drop out after a week and get a refund and study at my own pace.

  • @ymhsieh
    @ymhsieh 3 года назад +3

    JavaScript is also a dynamic typing language, and it is also much faster than Python...

  • @quantumjun
    @quantumjun 2 года назад

    that’s awesome, do you have a “deeper understanding” now. Can you make a video if so?

  • @Naton
    @Naton 4 года назад

    will python 3.7 type declaration or pydantic make python faster?

    • @lincolnsand5127
      @lincolnsand5127 4 года назад

      If the compiler adds support for compile time types

  • @mansodev
    @mansodev 4 года назад +4

    Python was just too slow for me so I just used lua, it’s faster and lightweight than python, and is quite similar.
    Btw lua is a scripting language but there is luaJIT

    • @patrickcampbell957
      @patrickcampbell957 3 года назад +1

      What were you doing where python was too slow?

    • @mansodev
      @mansodev 3 года назад +1

      @@patrickcampbell957 (sorry for the very slow response) Iwas trying to re=create the game of life in the python terminal, I eventually transferred and edited all code to be compatible to pygame, the game ran very slow and took ages to load even with cpython and PyPy which are Jit compilers for pyhton t was still quite slow, I quit the project. I then found out about lua and LuaJIT and since moved there

  • @pedrogalvez6399
    @pedrogalvez6399 4 года назад +3

    I personally noticed that Python was slower when writing some algorithms for image analysis of 3D objects. The algorithm was 1 Order of magnitude slower when written with Python compared to the same algorithm written in Java. But I love Python anyway

  • @hisamezero3388
    @hisamezero3388 2 года назад

    Wait. In for example the language ”rust” you dont either need to declare the datatype of a variable. You declare one with ”let name = value”. This is a compiling language. So why not make a compiling language but with the python syntax?

  • @bvg129
    @bvg129 3 года назад +1

    I had to parse lots of binary files using python. Then display it in maplotlib which embedded in tkinter gui.
    Python interpreter uses 17GB ram when parsed 200mb of binaries.
    Nightmare.
    Tbf, there is no numpy or any high-level features were used during development of that parser.

  • @baruchben-david4196
    @baruchben-david4196 4 года назад +4

    It's great that development time is so fast, but... Once you've done the development, your program is still slow, and will remain so...

    • @mantality312
      @mantality312 4 года назад +1

      No, it will not remain slow and no it will not seem slower. This is the problem with self taught programmers, they regurgitate these kind of non-sensical ideas with no true knowledge of computing. There is no noticeable difference in a python script vs a c++ script. The only time it matters is when the code has to interact directly with the RAM and processors which python can not, thus making it ‘slow’. This is typically only relevant in embedded systems and gaming which shouldn’t be written in Python anyway. For anything Python is meant to be used for there will never be a noticeable or recordable difference in speed.

    • @jameszack7158
      @jameszack7158 4 года назад

      Only a few microseconds slower. You won't even notice it

    • @jameszack7158
      @jameszack7158 4 года назад

      @@mantality312 exactly, we are not coding F-35's software with python. Therefore speed difference is negligible

    • @sanjay_swain
      @sanjay_swain 3 года назад

      @@jameszack7158 "you won't even noticed it" this says you have never worked on real life. In reality a microseconds is really really helpful especially when you are dealing with millions and millions of data.

    • @jameszack7158
      @jameszack7158 3 года назад

      @@sanjay_swain I don't think so. Every year computer hardwares and microprocessors double their speed. Maybe 20 years ago programs written in python were slow, but not today

  • @Luix
    @Luix 3 года назад +5

    Java is bytecode run in JVM. Java is slower than C C++ Go and Rust.

  • @brovoice6822
    @brovoice6822 3 года назад

    What do you think about pypy? I heard it speeds up code by 10x.

  • @ZaCharlemagne
    @ZaCharlemagne Год назад +1

    Nice explaination. 👍🔥
    There are also other ways to make Ur python code fast:
    JIT compilation. Because JIT compilation skips the whole process that goes on in the PVM and compiles code straight with an LLVM, it executes just as fast as C, or slightly slower, or in some cases (due to caching) faster.
    Another way is with Cython, which is a way of compiling python script to C++ code, for this you would need Ur python skills and some extra stuff from static typing to be able to write .pyx files (different from Ur regular .py files) you can achieve C++ speed with this as well. There's also another version called Jython (compiling python code to java)
    PS: I've tried all these out (except the Jython). Tho I don't code java, I do code C++.
    Concurrency and multiprocessing in python is actually straight forward, people only tend to use them where they don't necessarily apply (just saying) modules like asyncio can enable you convert a single thread python function into a coroutine simply by adding the function in the asyncio event loop or running loop. Also for anyone interested in performing multiprocessing in python I would advise you familiarise urself with mesh reduction.
    Also, most python modules / libraries / frameworks have key parts written in C or C++ or both...this is why one of the most computationally expensive tasks (machine learning) is done with python.
    And then, with the advancements in computer processors these days, the speed difference in alot of cases cannot even be perceived by humans (as you've already insinuated)

  • @rahulmandal6139
    @rahulmandal6139 3 года назад +8

    No worries,we got a lots of reasons to love Python🐍