Can Python Approach the Speeds of C?

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

ความคิดเห็น • 23

  • @DanielBoctor
    @DanielBoctor  ปีที่แล้ว +2

    WE HAVE A DISCORD NOW

  • @שגיא-ק5פ
    @שגיא-ק5פ 6 หลายเดือนก่อน +7

    That decorator is amazing, but the speed up in this case happens because it compiles the code and knows the answer beforehand
    If you will try the same example in c++ for example (you might need to use constexpr) you will see that the assembly code will be only a couple of lines because the compiler does all the work on the background

  • @dpkass
    @dpkass ปีที่แล้ว +14

    bro using java logo for js 1:02.

  • @Proprogrammer001
    @Proprogrammer001 ปีที่แล้ว +9

    I will share this with people just by virture. The meme you put at 1:05. Brilliant animations.

    • @DanielBoctor
      @DanielBoctor  ปีที่แล้ว +2

      Thanks for the feedback. Appreciate the shares too. Your a real one

  • @TheControlMastr
    @TheControlMastr ปีที่แล้ว +3

    Congratulations Daniel! You managed to lose me the first 10 seconds. I have to come back to this video after CS50 class 😅 Amazing Video!

    • @DanielBoctor
      @DanielBoctor  ปีที่แล้ว

      LOOOOOOOOL you're a real one @TheControlMastr

  • @sanderbos4243
    @sanderbos4243 ปีที่แล้ว +13

    So cool that you can just slap such a short decorator on your functions to do it with Numba

    • @DanielBoctor
      @DanielBoctor  ปีที่แล้ว +4

      I know! It really is something

  • @KalleLast
    @KalleLast 7 หลายเดือนก่อน +1

    a few months late but I implemented the same simple function and ran it on my machine and used 10,000 for the parameter value. ~3 trillion ns for pure python vs 1.4, 1100, 370 and 250ns for four consequitive runs for the jit version (speed didn't change much after that and hovered around 250).
    Running the same algorithm in c++ with -O2 it seemingly just optimized it to constant-time calculation as it ran in 10-20ns both when using 10,000 and 100,000 as the parameter.
    I wonder what could be a better microbenchmark that shows how well the jiting works for python and how close to c/c++ it can get.

  • @brockobama257
    @brockobama257 ปีที่แล้ว +2

    I knew it would be numba. Cool thing is if you have some complicated shit to do you can use cmake to create your own package.

  • @Darkev77
    @Darkev77 11 หลายเดือนก่อน +1

    Very interesting; I personally use Cython's Pure Python mode to compile time-intensive Python functions, and I wonder how it compared to Numba

  • @ImperialRoads
    @ImperialRoads ปีที่แล้ว

    this taught me how little chicken wings float in the equator of the earth

  • @komitetgosudarstvennoybezo5097
    @komitetgosudarstvennoybezo5097 6 หลายเดือนก่อน

    JavaScript Java logo very epic

  • @Ceelbc
    @Ceelbc ปีที่แล้ว +2

    It does not work in python 1.12.

  • @erikkonstas
    @erikkonstas ปีที่แล้ว +8

    This is simply not possible, a script running under a VM will never be as fast as a native executable with the same algorithm and task...

  • @josebr0
    @josebr0 9 หลายเดือนก่อน

    Thing is, numba isn't 100% compatible with numpy. Try using argmin or argmax. It simply doesn't work in nopython mode. It's really a shame.

  • @chenuka223
    @chenuka223 7 หลายเดือนก่อน

    Bros using Java logo on JavaScript

  • @myname-mz3lo
    @myname-mz3lo 10 หลายเดือนก่อน

    hacking tools are about to get much faster

  • @manupro1698
    @manupro1698 ปีที่แล้ว +10

    Why Python is faster?
    Because is using c

    • @greenwaldian
      @greenwaldian ปีที่แล้ว

      I don't get it

    • @SimGunther
      @SimGunther ปีที่แล้ว

      ​@@greenwaldianJIT is not (usually) C: numba is aware of the platform running the code in order to create the correct machine code in a write-executable block of memory that represents the function defined as python code.
      When defining I/O heavy code, the performance boost from JIT is negligible compared to math heavy code.

  • @peterjansen4826
    @peterjansen4826 5 หลายเดือนก่อน

    That is cheating because it isn't Python which is doing the work, you are not using Python, just Python-syntax. It is like driving a 90 year old woman in a car and then having her being faster than Usain Bolt. Sure, because the car-engine is doing all the work. Obviously I am not against making the code run faster but it doesn't solve the problem that too many people who learned programming are too comfortable with using Python and are using it for things which it just isn't suitable for, unless you do tricks like this. I can easily tell when a program uses Python or another interpreter-language (but usually it is Python), you can easily feel that the program starts slower, is slower with the GUI (when you open a window from a context-menu or whatever) and all that. Examples are Thunderbird and Lutris. I still use it but it is noticeable and if I would know of software with equivalent features but which uses a compiled language then I would switch.