Python vs JavaScript - side by side comparison

Sdílet
Vložit
  • čas přidán 31. 07. 2022
  • Python vs JavaScript test of the relative performance.
    As an example I took basic prime-finding algorithm with N² complexity.
    All found primes are stored in a list/array and as the result scripts print the length of the list/array.
    I tested a relative speed of code writing, including typos.
    And the Python and JavaScript performance.
    Python vs JavaScript - side by side comparison
    • Python vs JavaScript -...
    FOLLOW ME:
    Telegram: t.me/red_eyed_coder_club
    Twitter: / codereyed
    Facebook: redeyedcoderclub
    MY COURSES:
    / index-of-courses-54382548
    or
    red-eyed-coder-club.github.io...
    #python #javascript #redeyedcoderclub

Komentáře • 127

  • @RedEyedCoderClub
    @RedEyedCoderClub  Před 2 lety +20

    I intentionally didn't use special Python algorithms for primes. I compared language "efficiency" using dumb algorithm implementation for both languages and equal language "tools"
    Follow me @:
    Telegram: t.me/red_eyed_coder_club
    Twitter: twitter.com/CoderEyed
    Facebook: fb.me/redeyedcoderclub
    Website: red-eyed-coder-club.github.io/

    • @unton83
      @unton83 Před 2 lety

      ТГ канал без возможности комментировать?

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před 2 lety

      @@unton83 пока да. Но можно здесь

  • @jamesprice4074
    @jamesprice4074 Před 11 měsíci +23

    Came for the information, stayed for the background noise.

  • @gianluke
    @gianluke Před rokem +39

    This is just because Python integers are boundless integers (like BigInteger in Java), while JavaScript numbers are fixed-size floating point numbers. This is the same reason Python 3 is usually slower than Python 2 (which used fixed-size integers when possible).

    • @pylsur2024
      @pylsur2024 Před 5 měsíci +2

      That's right, 6.3 seconds here with using numpy and numba. With doing some algorithm optimizations I get down to less than 0.5 seconds for this in python.

  • @suomynona7261
    @suomynona7261 Před rokem +1

    Awesome video, great channel name

  • @soufianta8374
    @soufianta8374 Před rokem +4

    Hi. Very dumb programming question probably but how does the function deal with the different return values of the different blocks inside of it (for and if blocks)? If if the if block returns “false”, the for block returns “true” anyway or did I misunderstood something? Thanks.

    • @AdityaGowda2000
      @AdityaGowda2000 Před rokem +9

      Return statement means function call is over. So 2 return statements will never be execuited.

    • @Doonutzs
      @Doonutzs Před rokem +11

      As soon as you return the value you get out of the function. You could have an if with a return and then a simple return at the end of the function. If the if condition is fulfilled the last return will never be executed

    • @soufianta8374
      @soufianta8374 Před rokem +2

      @@Doonutzs thanks Kuroox. It's clear now.

    • @Doonutzs
      @Doonutzs Před rokem +2

      @@soufianta8374 you're welcome mate :3

  • @loftyTHEOWNER
    @loftyTHEOWNER Před 10 měsíci

    ok but what if you use tuples or numpy or numba?

  • @SnehilKankran-qe8si
    @SnehilKankran-qe8si Před 7 měsíci +9

    For a experienced devolper , Js is easily readable too

    •  Před 3 měsíci +1

      Me tooo

  • @ahmet-akin
    @ahmet-akin Před 3 měsíci +4

    I think node.js is better. We can already make code writing shorter in node.js.

    • @atlantic_love
      @atlantic_love Před 2 dny +1

      But then you're asking the user to have node.js on their system. Or to rely on a CDN that could fail at any time.

  • @TdadadT9
    @TdadadT9 Před 2 lety +20

    Its just python with C implementation under the hood :) Just use pypy in order to achieve best performance in CPU bound operations.

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před 2 lety +4

      You are right. But nevertheless I was a bit shocked, because the difference is huge.

    • @user-kn6uu8cc6l
      @user-kn6uu8cc6l Před 2 lety +2

      @@RedEyedCoderClubAlso try use list comprehension insteed of loop, it can increase speed

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před 2 lety +11

      I tried to use similar language tools, and JavaScript has no list comprehension. And btw when I used a list comprehension (I tried it) the difference is not so significant as it seems to be.

    • @blackjew6827
      @blackjew6827 Před rokem +1

      By that point just use C / C++

  • @waterdrop4572
    @waterdrop4572 Před rokem

    Shu yotube pyhton da yozilganmi?

  • @Alexey-gp7vc
    @Alexey-gp7vc Před rokem +12

    Yeap, CPython have no JIT (in this version), so... But if you compare Py and JS in more real world scenario with db and async network things - you can't see much difference. Mostly JS faster. But sometimes Py can be faster bc of the best integration with C.
    Btw, if you need speed - you use Numpy or PyPy/numba/pypyc or Cython. Or even Java, Go, Rust, C, Fortran, etc 😀

  • @manoharrajput8660
    @manoharrajput8660 Před rokem +1

    Any one help me to choose my next course about programming, My goal is data analyst and I have knowledge about SQL and now I would like to learn programming language but I am not belong from engineer background so which one is better for me either python or java?

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +1

      For Data Analysis you need Python, and not Java

    • @mb-kw9es
      @mb-kw9es Před rokem

      ​@@RedEyedCoderClub how about developing an android apps

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem

      @@mb-kw9es I don't get your comment

  • @arun-poudel
    @arun-poudel Před 2 měsíci +1

    Mojo is comming 🔥🔥🔥🔥🔥

  • @francko.j
    @francko.j Před rokem +7

    instead of return put yield in python and see the power of python

  • @im_vanich
    @im_vanich Před 11 měsíci

    Не сходится.
    Питон быстрее.
    Что за версия у вас?
    Проверяли в 3 человека на разных компах.

  • @JohnJohnson-ch6xq
    @JohnJohnson-ch6xq Před 2 měsíci

    I have been studying for cloud computing.
    I want to know if I should consider JavaScript or Python?
    Please advise.

  • @SnehilKankran-qe8si
    @SnehilKankran-qe8si Před 7 měsíci +2

    If you think 9.4sec is fast
    Use bun js to see the ultimate speed of JavaScript

    • @arun-poudel
      @arun-poudel Před 2 měsíci

      Use mojo 🔥 😂😂😂 no competition with any js runtime

  • @NH-ij8dz
    @NH-ij8dz Před měsícem +1

    On a i5 10600k and using multi processing you can get this down to 25 seconds on python. If you use pypy's Jit you can get it down to below 5s.
    def process():
    """Splits the task into multiple parts"""
    current_min = 2
    tasks_per_worker = 250001 // 12
    tasks = []
    for _ in range(12):
    tasks.append(
    multiprocessing.Process(
    target=, args=(current_min, current_min + tasks_per_worker)
    )
    )
    current_min += tasks_per_worker
    # Start and await tasks.
    for task in tasks:
    task.start()
    for task in tasks:
    task.join()

  • @jorge.barcelos
    @jorge.barcelos Před 9 měsíci

    I did the same test, same algorithm, same python version in wsl. Result: 0.06s user 0.00s system 99% cpu 0.061 total

  • @ktmar4276
    @ktmar4276 Před 2 lety

    I am surprised🦎

  • @NewLondonMarshall
    @NewLondonMarshall Před 2 měsíci

    The code formatting on the JavaScript side hurt me. No spaces in the for loop variable declaration check and increment, no space between the closing parenthesis and the opening curly brace. Ouch

    • @smash3689
      @smash3689 Před měsícem

      You can write however you want. Blame the op. If you want to force some formatting, use linter.

  • @Fayroll5
    @Fayroll5 Před 6 měsíci

    Python: compiles everything then runs
    Js: compiles 1 line and runs it

  • @ThankYouESM
    @ThankYouESM Před rokem +9

    Was super excited when first clicked because I thought this would finally show me how to swap each Python syntax to become Javascript syntax. However... OpenAI Codex is somewhat helping me build such an app, held back because the input allowance is far too limited whereas shortening the script keeps breaking it far too much.

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem

      Didn't get your point

    • @ThankYouESM
      @ThankYouESM Před rokem

      @@RedEyedCoderClub I thought this video would compare each syntax side-by-side for us to create Javascript projects from our Python scripts near as possible.

    • @Anastasia-cv4ld
      @Anastasia-cv4ld Před rokem +2

      @@RedEyedCoderClub he thought this video would be a sort of guide on how to convert a python program to a JavaScript program

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +1

      @@Anastasia-cv4ld For a minute? Ha-ha!

    • @jss_developer1432
      @jss_developer1432 Před rokem +2

      @@RedEyedCoderClub no, just like a quick side by side comparison of lets say variables, object,arrays,functions, setup, other js features, etc...

  • @thiagom5195
    @thiagom5195 Před 23 dny

    I think that this is not a good python code, when do in python range(2, 250001) it will create a list with each element from 2 to 250001 before do the "for". this create a horrible performace code.

  • @tah9r
    @tah9r Před rokem

    What is the color theme in this video?

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +1

      I used NvChad distribution in this video, and it uses One Dark theme.
      nvchad.com/

    • @tah9r
      @tah9r Před rokem

      @@RedEyedCoderClub thank you

  • @sergeyshevtsov5125
    @sergeyshevtsov5125 Před 2 lety +10

    Wow. Huge gap between them

  • @albumin30days90
    @albumin30days90 Před 2 měsíci +1

    never use loops in python
    rule #1
    of 1 rules

  • @KAMELLTDK
    @KAMELLTDK Před 11 měsíci

    Rise for Py

  • @avbolshakov
    @avbolshakov Před 2 lety

    nvim? not atom?))

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před 2 lety +1

      In this video I used nvim, because it's loaded instantly.

  • @mohit84604
    @mohit84604 Před rokem +1

    node js is blazingly fast

  • @Ryguy12543
    @Ryguy12543 Před 6 měsíci

    now do this with node.js and fastapi.

  • @revengerwizard
    @revengerwizard Před rokem

    Comparing a traditional interpreter with a JIT compiler…

    • @FlanPoirot
      @FlanPoirot Před 11 měsíci +1

      python has had 20 years to move into jit compilation and decided not to, instead it became a VM language with a unstable instruction set (meaning it's a moving target and people can't write a compiler using it as IR). in my book that's kinda python's fault for neglect performance and a whole slew of tooling that was essential.
      they're trying to slowly improve the language now but by now there's too big a baggage and the effort will take years and years and idek how much they'll be able to achieve

    • @revengerwizard
      @revengerwizard Před 11 měsíci +1

      @@FlanPoirot I know, but still comparing the two rather different implementations doesn't do any justice.
      Comparing C vs Python for example wouldn't give you much information, out of the fact that one is statically compiled while the latter is a traditional bytecode interpreter.
      But it's true, CPython implementation is pretty much a big mess overall.

  • @igweogba6774
    @igweogba6774 Před rokem +5

    To me Javascript is the best programming language. It runs in the browser, you can build everything from desktop apps to web and mobile apps with it and it is also pretty fast.

  • @Aravindudhaya
    @Aravindudhaya Před 2 měsíci

    Python execution speed very slow. Any way both technologies to have know our holding our jobs.

  • @AshtonMotana
    @AshtonMotana Před rokem

    If JavaScript is thus much quicker than Python, then surely JavaScript would be better for data analysis.

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +2

      Of course it's not better, like not better neither C++ and Go, and Rust. Python has the most minimalistic syntax - and it's the key.

    • @AshtonMotana
      @AshtonMotana Před rokem +1

      @Red Eyed Coder Club the example of the difference in syntax is negligible. The performance of JavaScript far outways this difference in syntax. I would like to see a comparison in performance regarding cleaning a CSV file of those pesky commas that are separating the same cell strings to prevent data misalignment in an automated fashion, then index and run through a simple algorithm that compares 10 columns of data and performance a date difference, creating new columns with that difference. With my JavaScript full stack app, I can clean and index a CSV with 89 columns and 750 thousand rows of data, in 7.5 seconds, and about another 7 seconds to run through the algorithm.

    • @brogolem35
      @brogolem35 Před rokem +1

      @@AshtonMotana (From what I see)The performance is not a major problem for professional use because they will use third party libraries like NumPy (which use C under the hood) or use tools like PyPy and Cython (and maybe Mojo in the future). The only people that sufferm from Python's speed are newbies (including myself) and CS students that are forced to write big and complicated programs without any third party tooling (also myself).

    • @rea1m_
      @rea1m_ Před 11 měsíci

      @@RedEyedCoderClub js syntax is pretty minimalistic too

  • @leimai7611
    @leimai7611 Před 8 měsíci

    Sorry, I need one hour of this stuff.

  • @alien432hz9
    @alien432hz9 Před měsícem +1

    Javascript comes from the island of Java.

  • @dio_nellas
    @dio_nellas Před 6 měsíci

    Use numpy

  • @ayami123
    @ayami123 Před rokem +1

    lol you use if else? why not use ternary operations LOL

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem

      First of all if/else is more readable, secondly all big guys like Guido van Rossum, Andrey Svetlov, Yuri Selivanov, developers of Django and Flask, and many others use if/else. I never see ternary operator in significant products, because the readability counts.

    • @ayami123
      @ayami123 Před rokem +1

      @@RedEyedCoderClub i prefer cleaner code though

    • @JuriBinturong
      @JuriBinturong Před rokem

      @@ayami123 coding is meant for humans not the machine.

    • @ayami123
      @ayami123 Před rokem +1

      @@JuriBinturong lol basic programmer know how to use ternary plus it's much cleaner than if

    • @AlphaDragons60
      @AlphaDragons60 Před rokem

      @@ayami123 He didn't use if/else, he used only if and you can't use ternary operation here anyway since the code is
      for(let i = 2; i

  • @ibrahimoglu
    @ibrahimoglu Před 2 lety +1

    🤔

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před 2 lety +1

      Yep, tomorrow I'll publish a video which is much more interesting and even a bit shocking.

  • @chillydoog
    @chillydoog Před rokem

    I got pynk eye

  • @nagamanickam5702
    @nagamanickam5702 Před rokem +68

    Python 3.11 is 25% faster, python 3.13 will be 5 times faster.. soon we will beat JS 😜

  • @hellelo.5840
    @hellelo.5840 Před rokem

    Python is more memory efficient.

  • @sgmvideos5175
    @sgmvideos5175 Před rokem +1

    that programming part was like... eh... I'd say made by somene who just wanted python to win... you could write JS version like this:
    for (let i = 2; i < n; i++) if (n % i == 0) return false; return true;
    or even
    for (let i = 2; i < n; i++) if (!(n % i)) return 0; return 1;
    it might not look so good, but it's way to make code shorter

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +14

      Are you kidding? If I wanted Python to win I would use special Python libraries like numpy, scipy etc. thousands of them.
      Your suggestion saved only 9 chars, but lost the readability. Awful TBH.

    • @sgmvideos5175
      @sgmvideos5175 Před rokem +1

      I mean, the only difference in these codes is the for loop syntax, you don't even need brackets there since it's so short...

    • @RedEyedCoderClub
      @RedEyedCoderClub  Před rokem +1

      ok, thank you for the comment

    • @Eckster
      @Eckster Před rokem

      Just return the boolean directly.

    • @rikoananda6189
      @rikoananda6189 Před rokem +1

      It can be even shorter and faster with this syntax:
      for(let i=2;i

  • @prietjepruck
    @prietjepruck Před rokem

    in Processing language on a Ryzen 7950x it took 2.8 sec.😀 Python is just ridiculously slow.🤮
    int N = 250_001;
    int prime[] = new int[N];
    boolean isPrime(int n) {
    for (int i = 2; i < n; i++) {
    if (n % i == 0) return false;
    }
    return true;
    }
    void setup() {
    surface.setVisible(false); // do not show the graphics canvas
    int t = millis();
    int teller = 0;
    for (int i = 2; i < N; i++) {
    if (!isPrime(i)) continue;
    prime[teller] = i;
    teller ++;
    }
    println(millis()-t);
    }

  • @WonderSpace4U
    @WonderSpace4U Před rokem

    JavaScript Best of the best

  • @sashankshekharshukla2575
    @sashankshekharshukla2575 Před 4 měsíci

    CPython is way faster than JavaScript.

  • @fuunnyvideospeedrun
    @fuunnyvideospeedrun Před rokem

    I'm sitting and waiting for js + ffmpeg to split a 30 minute video into 12 parts, and think maybe python would do it faster...
    all video about python: im turtle bro...

    • @learntechbasics
      @learntechbasics Před rokem

      Ffmpeg will take its sweet time irrespective of whether you use python or javascript

    • @trollface1994
      @trollface1994 Před rokem

      i am groot.