How Slow is JavaScript Really? JavaScript vs C++ (Data Structures & Optimization)

Sdílet
Vložit
  • čas přidán 19. 04. 2021
  • Is JavaScript really that slow? Or is that just a leftover impression from the old days?
    Patreon: / simondevyt
    Follow me on:
    Twitter: / iced_coffee_dev
    Instagram: / beer_and_code
    Github: github.com/simondevyoutube/
    In this video we talk a bit about JavaScript vs C++, and the performance difference between them. We'll talk quickly about the history of JavaScript before working through a few small benchmarks to compare performance between them, using various optimization levels for gcc. It's kind of interesting to see how much JavaScript's performance has evolved with JIT (just in time) compilation since the early Netscape days. The v8 team has made enormous strides in performance and is narrowing the gap with C++ year by year. We'll also walk through some examples of what you can do with your basic C++ code to squeeze more performance out, either by using better compiler flags or SSE/AVX intrinsics to get better usage out of your CPU.
    What's covered:
    * Super brief history of JavaScript and V8
    * Benchmarks and comparison of JavaScript vs C++
    * SSE and AVX intrinsics
    * gcc -Ofast and float associativity
    * Some closing thoughts on JavaScript's performance today, as well as C++.
    Speed, Speed, Speed: JavaScript vs C++ vs WebAssembly:
    • Speed, Speed, Speed: J...
    Godbolt:
    godbolt.org/
    Wikipedia:
    en.wikipedia.org/wiki/JavaScript
    en.wikipedia.org/wiki/Associa...
    Various blog posts from V8 team:
    blog.chromium.org/2010/12/new...
    v8.dev/blog/10-years
    v8.dev/blog/launching-ignitio...
    v8.dev/blog/adaptor-frame
    v8.dev/blog/high-performance-...
    v8.dev/blog/fast-super
    v8.dev/blog/preparser
    v8.dev/blog/spread-elements
    v8.dev/blog/background-compil...
    v8.dev/blog/fast-properties
    v8.dev/blog/fast-for-in
  • Věda a technologie

Komentáře • 904

  • @PaweMateuszBytner
    @PaweMateuszBytner Před rokem +97

    i am maths and informatics teacher on private University in Poland, and it's rather distinctive that many students I teach are already programmer technicians / professionals with some market experience. I heard many times about superiority of C++ from people worried about performance when the lecture was about C#, JS or Python. Then those same people were completely missing the point on the lecture on algorithms and data structures. I notoriously see invalid solutions to rather simple problems - sometimes just tweaked to pass provided examples- and code that is completely unaware of data structures other than arrays, or maybe aware of linked lists, but using them like arrays. Dude, your C++ code will be slower than my JS code for not-small-enough data if you don't know what data structure or algorithm when to use

    • @simondev758
      @simondev758  Před rokem +23

      Absolutely, just focus on getting the basic approach decent. I've spent years working with C++ devs, like you have, and despite all of their "worries", most of them produced pretty bad code

  • @gugiserman
    @gugiserman Před 3 lety +717

    Most people complaining about your language of choice probably can't write half the logic you do

    • @kevinjohansson3923
      @kevinjohansson3923 Před 3 lety +12

      Yeah, and then they write something in C++ which is buggy at best because they can't handle it at all. I'd rather master a higher level language before jumping to low level stuff if I were them but nope.

    • @brawlgammer4424
      @brawlgammer4424 Před 3 lety +51

      @@kevinjohansson3923 But here's the catch: being really good at a low level language teaches alot more about programming fundamentals than a high level one. What you described are bad programming practices and that is an issue on its own, a programmer with bad practices in low level languages will probably port them on to another language in a similar fashion. I started programming in C and even though i'm no master i now have a very good grasp on programming fundamentals and most of what i've learned is transversal.

    • @dufferzzzzz
      @dufferzzzzz Před 3 lety +8

      @@brawlgammer4424 Agreed. I started learning to code with JS, learned basic C to understand types better, alongside memory allocation. Then I moved on to learning TypeScript, C++ and GoLang.. Investing time in C and C++ significantly improved my understanding.

    • @thewarriors3048
      @thewarriors3048 Před 3 lety

      @@dufferzzzzz As someone who is about to start learning programming, I am thinking on which language to start with. I know I can pivot down the road, and ultimately, low level languages are what intrigue me, however I don't think they're smart for genuine progression as a beginner. It seems like JavaScript is truly the best bet even though web development isn't too interesting to me as of now.
      Edit: And of course there's Python and it's vast amount of libraries. I just don't know of any decent beginner projects that can be done with low level languages. It's always really awesome, advanced projects. Open source is great, but really how much can you truly contribute as a beginner?

    • @dufferzzzzz
      @dufferzzzzz Před 3 lety

      @@thewarriors3048 I always have a hard time deciding on projects too. I chose to start with javascript because it is fairly easy, but as 'easy' as it is, it will cause you just as many headaches because of how it works with types.
      I understand your view on Web dev not being interesting. When I first started, I learned html, js, css, node and ejs templating.. Didn't enjoy it overly much. Creating multiple basic CRUD applications soon got boring. I decided to learn React and investigate CQRS and microservices architecture in the cloud.. Honestly 1000x more interesting in my opinion... Terraform, kubernetes, RabbitMQ, Kafka, gRPC, Jenkins build pipelines.. Even github actions.. There really are a lot of brilliant technologies involved when you start looking more full-stack than just front end. Also if you are using microservices then you can have them essentially in any language you want. Golang is my personal go to, and you can take full advantage of the languages choose to write them in. JS is slow (sue me, haters) , and sometimes a pre compiled c++/go binary will run 4x faster so it just makes a lot more sense to use.
      First language is always the hardest, keep persisting and you will recognise patterns.. Good luck to you!

  • @Ferdam
    @Ferdam Před 3 lety +492

    I've heard you can beat most languages if you write your stuff directly in binary 🙃

    • @Rssks
      @Rssks Před 3 lety +128

      Haha! Why not just wire yourself to the cpu and tap your bits in manually 🤣 ?

    • @simondev758
      @simondev758  Před 3 lety +380

      Even faster if you just build it right into the hardware. Only n00bs don't build the silicon themselves.

    • @tythedev9582
      @tythedev9582 Před 3 lety +114

      @@simondev758 I have a nice game idea, I just need to go mine those precious metals first

    • @andrewdunbar828
      @andrewdunbar828 Před 3 lety +19

      Nah, I used to program in binary machine code when I was a kid because I didn't have an assembler. Code is the same speed written that way as code written in assembly, but takes longer to write. BUT you CAN beat most languages if you write your stuff directly in Verilog or VHDL for an FGPA (-:

    • @blablabla7796
      @blablabla7796 Před 3 lety +13

      @@andrewdunbar828 that’s pretty cringe not making your own specialized hardware for each function.
      Kidding aside, using FPGAs are a little cheaty because of just how good they could be. I’m glad that we’re almost past having to use specialized FPGAs because GPU processing is becoming more and more accessible.

  • @filipe_paixao
    @filipe_paixao Před 3 lety +293

    episode 7: calling chemistry and electrical engineers to remodel all individual parts of all hardware pieces to be 100% oriented to the program we want

  • @LewiLewi52
    @LewiLewi52 Před 3 lety +876

    Bet u can squeeze out even more performance with Holy C.

    • @blocksrey
      @blocksrey Před 3 lety +15

      Lmao

    • @juliankandlhofer7553
      @juliankandlhofer7553 Před 3 lety +134

      who needs performance when you can have 3d graphics in your code?

    • @crynesssruns7364
      @crynesssruns7364 Před 3 lety +77

      Behold Assembly

    • @LordFers
      @LordFers Před 3 lety +23

      Terry would be proud of you boy.

    • @Xman_9
      @Xman_9 Před 3 lety +25

      you can squeeze out even more performance with byte code than holly C. even better you can build your own computer to squeeze more performance!

  • @dempa3
    @dempa3 Před 3 lety +400

    I think it'd be interesting to learn from you how to write efficient code in general (I understand you have worked with optimizing other people's code for games), and maybe a "learn efficient JavaScript together" series of videos.

    • @misterl8129
      @misterl8129 Před rokem +5

      please please please, as a semi sinior js dev it would be a great step for my carreer. Like a reproduction list of videos :D

    • @Tiptup300
      @Tiptup300 Před rokem +4

      Learn more of how data moves around on computers.
      Data Structures + Algorithms = programs

  • @CottidaeSEA
    @CottidaeSEA Před 3 lety +43

    How you write the code is often more important than what language you write the code in. Understand what operations are efficient and which are not. Choose accordingly when performance matters.

    • @BryceDixonDev
      @BryceDixonDev Před 4 měsíci +1

      An efficient implementation will always be faster than a poor/naïve implementation, regardless of the language used for either case.
      If you implement an N^3 algorithm in C++, it'll trend slower than a log(N) implementation in even the slowest interpreted language.
      Shocks me that self-proclaimed "experts" miss that.

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

      @@BryceDixonDev Yeah, it's also why performance benchmarks are a sham. At best a marketing strategy.
      Python has awful performance for example, but it can be extremely performant if it is used to call compiled C functions. There'll be some overhead, but it won't be crazy slow as if everything was written in native Python. So knowing the strengths and weaknesses of the language is just as much skill as writing the code itself.

  • @andrewsides7250
    @andrewsides7250 Před 3 lety +169

    Just checked out your instagram. Thought you were a 60-something year old man until now. Love your channel!

    • @simondev758
      @simondev758  Před 3 lety +118

      I'm 60 at heart.

    • @dgcp354
      @dgcp354 Před 3 lety +3

      @@simondev758 isn't comparing language what newbie do, cuz I don't think js and c++ are meant to be used for the same goal, I'm disappointed at this video, I don't think people use c++ to build a website or use js to build a game (no idea), am I wrong

    • @telnobynoyator_6183
      @telnobynoyator_6183 Před 3 lety +12

      @@dgcp354 he used js in his videos, probably because it's easy for beginners to understand and ppl started shitting on him bc of that. So he made a video saying js isn't that bad.

    • @dgcp354
      @dgcp354 Před 3 lety +6

      @@telnobynoyator_6183 oh I get that, he keeps saying js ain't bad in the video, that's why I said to myself why even compare them at all, every language has a purpose to shine on. every language is not intended to do everything. and trying to convince js haters is like pouring water on a stone.

    • @Veso266
      @Veso266 Před 3 lety +1

      How old are you then?

  • @cynical5062
    @cynical5062 Před 2 lety +61

    Great video! One thing I feel like you forgot to mention at the end is that, while yes, the V8 team is going to keep finding optimizations, so will the people working on GNU's GCC G++ compiler. It's essentially a race to see who can find clever optimizations faster.

    • @simondev758
      @simondev758  Před rokem +18

      Definitely. I highly doubt V8 will ever catch up, but they'll probably get a little closer each year.

  • @tuomaskoivistoinen6476
    @tuomaskoivistoinen6476 Před 3 lety +158

    I think really nailed it with the "you get to understand your code" and that it "sucks to have a compilers job". The less constraints a language has, the more performance you can squeeze out. But the more constraints it has, the more transparent it gets. High level languages should never beat system level languages on performance, but it's nice to see the difference isn't too bad.

    • @simondev758
      @simondev758  Před 3 lety +37

      When I grow up, I really don't want to be a compiler.
      Yeah it's pretty cool to see how much work V8 has put into this, some real wizards over there.

    • @Spongman
      @Spongman Před 3 lety +10

      this is true in practice, but not necessarily so. you could have a "do what i mean" high-level language that generates the provably-optimal solution for whatever high-level request you give it and it would always be as fast or faster than hand-written code. there's no requirement that high-level languages be slower, that's just where we are right now.

    • @kosnk
      @kosnk Před 3 lety +3

      I think we now recognise that high-level language compilers are starting to outsmart an average low-level coding (especially for functional languages, where math can give compilers more hints).

    • @ThePC007
      @ThePC007 Před 3 lety +8

      Ironically, using JS actually makes me have a compiler's job. Not when it comes to optimisation, but when it comes to find errors that should be found during compile time, but aren't (dynamic typing can be a real bitch, especially during refactoring).
      That said, scripting languages like JS, Lua, and the likes are great for learning how to code. I wouldn't chose JS over C++ even in situations where performance doesn't matter at all, but I'm happy that I didn't have to choose C++ as my first language to learn.

    • @kosnk
      @kosnk Před 3 lety +1

      @@ThePC007 , did you have a chance to try TypeScript? Strict types with syntax otherwise identical to JS. For the past few years I start my web projects only with TypeScript.
      Also, there's an interesting project, called AssemblyScript -- its a low-level language, compiled to WebAssembly, while being similar to TypeScript in syntax.

  • @490o
    @490o Před 3 lety +3

    Thank you for actually putting the results next to each other. So many CZcamsrs who do benchmarks expect you to scrub around to compare results.

  • @malcolmholmes115
    @malcolmholmes115 Před 3 lety +23

    Your voice is so calm and watching your videos is just like a meditation

  • @awweather
    @awweather Před 3 lety +9

    I haven't really seen anyone do what you do in JS. Keep it up! As someone who's also working on a 2d mmorpg in javascript, I have already learned a ton of stuff from your videos

  • @jimpa7011
    @jimpa7011 Před 3 lety +14

    Im so glad I found this channel, Simon you make great videos.

  • @Atmos41
    @Atmos41 Před 3 lety +18

    That comment in the beginning, comparing Java to Javascript... The guy who wrote that clearly has not programmed with any of those languages if he thinks they are similar xD

    • @IndellableHatesHandles
      @IndellableHatesHandles Před 3 lety

      JS looks no more like Java than any other language based on C syntax. Heck, even Python has more similar class syntax to Java.

  • @redstone_mason
    @redstone_mason Před 3 lety +363

    Why would you use C? Assembly is much faster

    • @Gol_D_Roger_The_Pirate_King
      @Gol_D_Roger_The_Pirate_King Před 3 lety +60

      Binary is much faster

    • @neinnine4592
      @neinnine4592 Před 3 lety +13

      Actually binary would be faster!!

    • @nathanadhitya
      @nathanadhitya Před 3 lety +12

      Unable to imagine somebody writing "light" for optical processors for "truly fast"

    • @gaafts
      @gaafts Před 3 lety +32

      To my knowledge, C code is compiled to assembly code, which is compiled to binary. In other words, it's compiled to binary anyway. There are some situations where assembly code can be faster than C code because you have outsmarted the C compiler with a faster way to do something. I can't imagine a single case where writing in binary will be faster than assembly.

    • @coopercone4293
      @coopercone4293 Před 3 lety +20

      @@gaafts You're right, but everyone above was joking around. Assembly is translated to machine code with an assembler, which uses a 1 to 1 mapping of instructions (for a given processor). Assembly is just a human readable version of machine code.

  • @kosnk
    @kosnk Před 3 lety +88

    The reality is that if an app runs slow -- it's likely that the code is the issue, not the language. Roughly speaking, in O(n) -- n's coefficient has much less impact than its power.
    Yes, JS won't outperform c++, but it has more than enough fuel for a modern app (while surely gamedev being always greedy).
    As they say, a released app is worth much more than a well-optimised asm file.
    Good luck and happy coding!

    • @simondev758
      @simondev758  Před 3 lety +6

      Well said.

    • @rabradek
      @rabradek Před rokem +1

      Unless you're using an interpreted language like Python, where you can expect 200x slower performance on each op when compared to a compiled language.

    • @Dev-Siri
      @Dev-Siri Před rokem +1

      ​@@rabradek Python can go fast too
      You just have to call C apis

  • @NathanHedglin
    @NathanHedglin Před 3 lety +5

    Great video as always Simon! Thanks

  • @emmanuelfelix5935
    @emmanuelfelix5935 Před 3 lety +2

    In the begining of the video I tought that you was forgeting important things of c++, but your final performance was impresive. great video!

  • @avi12
    @avi12 Před 3 lety +45

    How about a benchmark of JavaScript vs C++ vs C++ via WebAssembly?

    • @noahsmith2555
      @noahsmith2555 Před 3 lety +4

      I’ve seen you on the coding train discord lol. The internet is a small place.

    • @mateuszabramek7015
      @mateuszabramek7015 Před 3 lety +1

      But WebAssembly is not javascript - it's compiled from languages like C++ , Rust Or even Typescript etc. So comparing C++ with C++ seems stupid. What JS does is just loads WebAssembly in browser, but that's it.

    • @noahsmith2555
      @noahsmith2555 Před 3 lety +9

      @@mateuszabramek7015 WebAssembly is compiled to bytecode that runs on a stack-based virtual machine that is built into the browser, it is not native machine code. It is not comparing the languages’ speeds, it is just comparing the speed of the WebAssembly interpreter/VM interpreting WebAssembly bytecode, to the CPU directly executing native platform specific machine code.

    • @Justin73791
      @Justin73791 Před 3 lety

      @@mateuszabramek7015 What about we use asm then, as that's technically JavaScript (though processed by the the same engine as wasm) :D

  • @SusumoKakinotane
    @SusumoKakinotane Před 2 lety +3

    This is excellent, honestly, you make great content. And even at the end, you point out the possible issues or considerations to even try to squid some more performance. Out of this world, glad I found your channel.

  • @Artintrex
    @Artintrex Před 3 lety +64

    C++ is my favorite language but, I still find your content interesting. Performance you manage to squeeze out of Javascript clearly shows your experience and many lessons here can be applied to games in any language.

    • @shapelessed
      @shapelessed Před rokem

      I'm a web dev, and while I do agree that JS has way too many flaws, I do respect how they decided not to add things like macros...
      Although you can still overwrite a global prototype of arrays for example and V8 will then not be able to use faster prototype lookups and you cold possibly f up the entire program.

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

    Love this channel big time for the insightful & thoughtful content, but I'd genuinely listen to any amount of audio books you'd record

  • @wmcmurray
    @wmcmurray Před 3 lety +1

    I was wondering exactly that the other day, I'm glad you did this comparison !

  • @MuriloMielke
    @MuriloMielke Před 3 lety +145

    Did anyone already told Simon sounds like a Dark Souls NPC? I just got into the channel and couldn't help to think of it.

    • @nathanpointer7844
      @nathanpointer7844 Před 3 lety +11

      Praise the sun 🌞

    • @simondev758
      @simondev758  Před 3 lety +25

      So many not-fond memories of that game.

    • @solaris867
      @solaris867 Před 3 lety

      @@simondev758 Please fix your voice. You speak like something in your throat

    • @elidrissii
      @elidrissii Před 3 lety +7

      @@solaris867 Please fix your manners.

    • @illford6921
      @illford6921 Před 3 lety +5

      @@solaris867 yes change your voice, that you were born with.
      The voice if fine, sounds like a wise man if he had a long white beard I'd listen to everything he says. At that I don't get complaining about someone's voice pretty much just an insult

  • @Rssks
    @Rssks Před 3 lety +13

    Nice hands on testing! Results were as ~ expected but concept and context is what matters. By having fun in JS you open up dependency-free, ready to launch learning experience to wider range of novice fellows.
    Anything can be ported & fine-tuned for the final product :)

    • @Rssks
      @Rssks Před 3 lety

      Don't get me and my sloppy English wording wrong, I do praise your work!

  • @Retrosen
    @Retrosen Před 3 lety +2

    Your voice is so relaxing to hear dude! amazing content

  • @cat-.-
    @cat-.- Před 3 lety +18

    When you’re bottlenecked by a bunch of data operations often you need to....
    Cpp people: AVX!!
    Js people: Wasm!!!

  • @j.c.h.9891
    @j.c.h.9891 Před 3 lety +13

    What this tells me is "Know your tools!" so hard. Thank you.

    • @A1rPun
      @A1rPun Před 3 lety

      You are very bright that you derive that meaning from this video. Javascript has a specific purpose for the browser. The video didn't even mention nodejs which is basically the javascript engine pulled out of the browser.

  • @krazybubbler
    @krazybubbler Před 3 lety +4

    Love each and every video you upload SimonDev. Gold content as always!

  • @tuckerbeauchamp8192
    @tuckerbeauchamp8192 Před 3 lety +1

    Awesome video my friend!

  • @vinfern27
    @vinfern27 Před 3 lety +1

    Excellent works as usual. Thank you.

  • @ManasTunga
    @ManasTunga Před 3 lety +13

    Nice comparison !!! Js being a single threaded web language that does most of job async quite impressive compared to strongly typed compiled language like C++

  • @sps014
    @sps014 Před 3 lety +8

    Great insights.
    C++ Wasm vs JS will be a fair comparison as both will run in Browser.
    Need one video on that.
    Thanks.

  • @michaelmulholland4380
    @michaelmulholland4380 Před 3 lety +1

    Love the channel just subbed hoping for more great content! Thank u

  • @elliotcroteau5067
    @elliotcroteau5067 Před 3 lety +1

    great stuff dude !

  • @AndrewDevUA
    @AndrewDevUA Před 3 lety +12

    awesome content!! Thanks!

  • @soykike1991
    @soykike1991 Před 3 lety +3

    Hey awesome video just subscribed this is the kind of stuff I like to see, also there might be a way to optimize the javascript code, webworkers you can spawn to do some solid math operation, but might tend the start making your code more complex. For example for large arrays of vectors you can divide them into x quantity and spawn x workers I would love to see this compared to c++

    • @simondev758
      @simondev758  Před 3 lety +2

      Good idea, might be an interesting follow up video to compare threading.

  • @tomm.4447
    @tomm.4447 Před 3 lety +1

    Awesome content! You really helped me with my pet project, thank you!

  • @lucaslengyel8635
    @lucaslengyel8635 Před 3 lety +1

    Really cool video!

  • @IndigoCode
    @IndigoCode Před 3 lety +13

    Great video, thanks! I was a JavaScript naysayer until my first time getting my hands dirty with it, but nowadays I love the language.
    I've seen some other comments wondering about a WebAssembly comparison, I'd definitely be curious what your benchmarks look like in asm.js and WASM. Awhile back I did some comparison between JS and WASM for skeletal animation (via Emscripten, -O3) but my results (5x-10x) were pretty dubious because I wasn't really comparing apples to oranges - no typed arrays, tons of allocations in the JS version, etc.

    • @simondev758
      @simondev758  Před 3 lety

      Definitely would be interesting, pretty sure the v8 team did some testing in the video, was pretty close to native performance. And WebAssembly SIMD is a thing now too.

  • @CollinBaillie
    @CollinBaillie Před 3 lety +4

    I wonder how much the processor technology improvements are part of the JavaScript performance increase? It would be interesting to see a comparison of old JavaScript vs old C/C++ on an old CPU. Obviously the range of tasks would be more restricted.

  • @skilz8098
    @skilz8098 Před rokem

    Another metric that could have been looked at is when working with multidimensional arrays with nested for loops and how you index them while trying to maintain cache coherency (preventing more cache misses) as well as minimizing the use of the branch predictor. Data alignment and page swapping could be another thing to consider especially when reading / writing data to files... Memory layout and memory access is vital when it comes to finding bottlenecks within the source code to maintain a higher level of performance. Just as important as that is when you start to work with multithreading... When these techniques are involved and being used then compare the difference in performance between each language. Nice video BTW.

  • @markzuckerbread1865
    @markzuckerbread1865 Před rokem +2

    Came here from the ThePrimeTime video, glad I discovered this channel!

  • @alvarolloret948
    @alvarolloret948 Před 3 lety +16

    Keep the 3D JavaScript content! You are doing great and your videos are really unique ☺️

  • @pinch-of-salt
    @pinch-of-salt Před 3 lety +5

    Absolute legend!

  • @TurtleKwitty
    @TurtleKwitty Před 3 lety +24

    "You clearly havent shipped a game" optimization and language choice are far from the most important consideration when talking about completing projects, willingness to finish it is the most important and for some JS helps with that, its a fun language.
    You also mention that c++ has options, but you also have those options with js, you can go full wasm and even not use the dynamic types and go full typed if you needed to eek out more performance, theres always more to do if you really need it; JS will never be as fast as bare to the metal, but its so quick to write and work with its a viable tradeoff for many projects!

    • @circuit10
      @circuit10 Před 3 lety

      Isn't WebAssembly a completely separate thing? I guess it's a web technology that integrates with JS though

    • @Spartan322
      @Spartan322 Před 3 lety

      JS to WASM, while likely a bit more performant, is still likely to lead to bottlenecks that JS would be in-optimal for complex and larger projects that need robustness, another issue a lot of these discussions tend to forget is that static typed systems (alongside a lot of proper compilation steps and static analyzers) exist to reduce and prevent bugs caused by dynamic typing systems and provide heavier and clearer optimizations, and since JS and its derived transpiled languages don't really address that (aside from maybe Dart, but even then I would be real hesitant to say that, Typescript does it the Python way, which bogs down the runtime immensely) you can easily achieve a point where JS will fail and harm your development where any statically typed language wouldn't have. Note as well that typed JS is relying on runtime typing which detracts from the runtime. Its not to so much JS is bad, but its more so unsuited to this purpose and its paradigms and nature make long term development and project management beyond an utter chore, increasing development time often for the sake of looking simpler. (or it could become more complex in trying to become reasonable and now you've defeated the whole point of using it)
      For this specific case it will be fine since its a demonstration, the problems crop up when relying on JS infrastructure and paradigms and start trying to use it for production projects.

    • @TurtleKwitty
      @TurtleKwitty Před 3 lety

      @@circuit10 Think of it like writing a function in assembly and calling it from c++

    • @TurtleKwitty
      @TurtleKwitty Před 3 lety

      ​@@Spartan322 Unless youre trying to argue that assembly isnt suitable for large projects then wasm isnt any less suitable.
      Except that static typing potentially helping for bugs isnt something being forgotten by those of us saying that js is perfectly suitable for many projects, its purely being forgotten by those that refuse to accept that js can be. Is JS perfect for everything? God no. But is it perfectly suitable for many things? If its your language of choice then hell yeah. I wouldnt expect every game dev in the universe to magically drop pygame because a rnadom person decided that python wasnt the most performant language in the universe, well same goes for js. Wouldnt expect anyone to make the next AAA hyper realistic full physics sim open world MMO or whatever in JS, but same goes for many other languages and tools that are used for making games anyways *shrug*

    • @simondev758
      @simondev758  Před 3 lety +1

      Yeah that was my favourite quote. So much anger in it, gave me goosebumps. Loved it hah.

  • @HolyDemonRune
    @HolyDemonRune Před 3 lety +9

    I love watching these things.
    When I first started learning programming it was like reading the matrix falling numbers screen. Now, I love going through videos, going "I completely understand everything this code is doing... wait wtf is that?" It's actually really fun and leads me to learn more about this subject!
    It's also impressive, it allows you to see the difference between experience and knowledge. I can read and understand whats going on, but there's no way in hell I could've have done ANY of this. there's a chance I could have, given a year. It's not like I don't have the knowledge to do this but I lack the experience and wisdom needed to accomplish such feats. It's inspiring and mortifying at the same time; exciting but still a long ways to go.

    • @simondev758
      @simondev758  Před 3 lety +4

      You have exactly the right attitude to become an extraordinary engineer.

  • @EngineerNick
    @EngineerNick Před 3 lety +3

    This was amazing well made video :) I'd love one comparing python to javascript!
    I recently moved from python to rust... and I am wondering if I even need to go back :P

  • @kosnk
    @kosnk Před 3 lety +18

    But wait! There's more:
    SIMD is coming to webassembly in chrome 91 (not JS, but might boost the ecosystem).
    Again, great video, Simon! Thanks

    • @simondev758
      @simondev758  Před 3 lety +3

      Oh seriously? Didn't see that, very cool.

    • @kosnk
      @kosnk Před 3 lety +1

      @@simondev758 , afau, webassembly is still at its early stage, and will definitely improve in performance, abilities and dev experience. Also, there's an interesting project called AssemblyScript that compiles to wasm and looks similar to TypeScript -- quite fascinating.

    • @softwarelivre2389
      @softwarelivre2389 Před 2 lety

      @@kosnk AssemblyScript is pretty neat!

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

    Love it!

  • @skwtf
    @skwtf Před 3 lety +2

    Thank you! Can you start a beginners series on optimisation and best practices on common programming optimisation techniques, across different languages (if that's even a thing)?

    • @simondev758
      @simondev758  Před 3 lety +4

      That's what this series is!

    • @DFPercush
      @DFPercush Před 3 lety +2

      1. Don't bother optimizing things that don't matter. 2. Use the right algorithm. But above all else: 3. Remember the sage advice of financiers: cache is king.

  • @arminrosic9550
    @arminrosic9550 Před 3 lety +6

    This is great stuff. I am often very pleasantly surprised by just how fast JavaScript is.

  • @plokki456
    @plokki456 Před 3 lety +3

    Nice video! I would be very interested to see a comparison of the performance of webgl and opengl. I worked on a project using threejs a few months ago, and it felt like webgl was dead slow compared to what I'm used to in opengl.
    But maybe it's not that bad actually :)

    • @simondev758
      @simondev758  Před 3 lety

      I'm guessing there's a lot of overhead since you're so removed from the driver, going through JS then IPC's to the gpu process, etc. I'd think, but have no proof, that code running on the gpu should be similar.

    • @DFPercush
      @DFPercush Před 3 lety

      You can access a canvas's draw context directly from web assembly without going through the JS boundary, so it's not quite as bad as you're thinking. But you're still basically using the smart phone version of OpenGL ES. Not the fastest API out there but it's ok for some stuff.

  • @stuntman3614
    @stuntman3614 Před 3 lety +1

    Awesome video, what tool you used to get a side by side comparison of assembly and cpp code? Thx

    • @simondev758
      @simondev758  Před 3 lety

      Near the end? There's a site, godbolt.org, let's you dump in some c++ code and see the compiled output for various compilers.

  • @EngineeringFun
    @EngineeringFun Před rokem

    Simon, what presentation software are you using (the cool animated font and drawing)? I just need a name or a keyword. Thanks!

    • @simondev758
      @simondev758  Před rokem

      Which part? The black screens with titles? Those are google slides + me typing. The drawings are just any old paint program + editing out the menus

    • @EngineeringFun
      @EngineeringFun Před rokem

      @@simondev758 Amazing, thanks. Can you elaborate on the old paint program? Maybe I can find it.
      How about those 3D exemplifications of various programming concepts?
      Thanks!!!

  • @juliankandlhofer7553
    @juliankandlhofer7553 Před 3 lety +7

    This shows the exact reason you should always do benchmarks. Many times the performance differences are not as big as you think! Great Video 👍
    Also, the people hating on JS are probably the same people who then wonder why their Python code is slow 😁. V8 really is a miracle.

    • @NathanHedglin
      @NathanHedglin Před 3 lety +2

      Agreed. JS is mostly “bad” because of bad developers not because it’s inherently bad. V8 uses some crazy dark magic.

    • @Spartan322
      @Spartan322 Před 3 lety +1

      Javascript's biggest issue, (when it comes to this type of stuff) least for the last decade, has been the typing problems and its scalability issues for large projects, its a nightmare to lack qualified types in multi-person projects and runtime type checking doesn't do well at dealing with this, the lack of a dedicated compilation step and fully qualified static analyzers also really hampers the development and increases bugs, both of which start to outweigh the ease of which JS development brings. Its also never really fair to compare simple tasks in two languages, those simple tasks could be optimized down for any number of reasons because of the specifics of the language or the manner in which you solve a problem in one language is so drastically different from another that to compare them becomes utter nonsense. In C/C++ you have pointers and memory management, (and for quite a while now, compile-time capable execution in C++) something you never can get in Javascript, and that so utterly redefines the way you do things that it really doesn't work to compare Javascript to C++. All this isn't to say JS is bad, but its a tool not exactly suited to this type of development outside of demonstration, as long as everyone understands that if you're doing this stuff yourself, you shouldn't be making production code in JS for this case, its otherwise irrelevant to address in my opinion.

    • @astrotecn
      @astrotecn Před 3 lety

      i think the hate comes from the fact that the js community is fucking retarded with tons of frameworks
      the language itself isnt bad, the ecosystem though is fucking cancer

  • @V972
    @V972 Před rokem +5

    Huh.
    This surprised me.
    I'm also guilty of firmly sticking w/ "JS slow" because of prior experiences and general [outdated] opinion.
    However, these tests (as well as a small history course) shows that I'm wrong.
    And honestly, I'm glad to be wrong, I'm glad that JS is catching up even if it probably won't be able to fully do so (it's still good enough).
    Thank you for the video! You've been cropping up in my recommeded for while now and I haven't regretted a single video of yours that I watched. I think I'm gonna subscribe!

  • @IronFreee
    @IronFreee Před rokem +2

    I love JS, it's fun to use. I made a few graphical web apps and small web games with it for fun, usually with a bunch of friends in a few days.
    I used a lot of Typescript professionally, mainly in Angular, but I often got frustrated by the framework limitations.
    I remember one time when the client was complaining about a pixel gap that could have been quickly solved in JS but was left because, with Angular, we couldn't do anything about it.

  • @spacedoohicky
    @spacedoohicky Před 3 lety

    Will web assembly allow JS massaging as well? Though there already is some JS massaging with bitwise operators.

  • @AntonioNoack
    @AntonioNoack Před 3 lety +3

    Memory layout indeed can be a problem, which the compiler cannot fix. Some CPUs only have (4/8 element) aligned loads.
    For my R5 2600 nothing happened when I used it incorrectly though ^^.

  • @cykboy3254
    @cykboy3254 Před 3 lety +24

    i would like to see the same performance test ran in nodejs. id expect it to be faster than in a browser

    • @ThePapanoob
      @ThePapanoob Před 3 lety +1

      What makes you think that?

    • @Rssks
      @Rssks Před 3 lety +7

      Nodejs runs v8, your browser runs v8. There should be no difference in performance of code execution. The only thing you might save in nodejs is the lack of the browser hugging up your cpu and memory (free unused resources) and that's about it :)

    • @cykboy3254
      @cykboy3254 Před 3 lety +2

      @@Rssks well, thats my point - the browser runs a v8 instance per tab and theres other factors to consider in that process that could use cycles/resources. plus nodejs has some specific architecture designs for async workloads which would be an interesting performance comparison for in modern c++

    • @cykboy3254
      @cykboy3254 Před 3 lety +2

      @@Rssks scoping also makes a big difference between browser and node, but writing good code that shouldnt be a bottleneck

    • @cykboy3254
      @cykboy3254 Před 3 lety +1

      @@ThePapanoob resource allocation. the c++ code was ran in its own process, the js code has to deal with the browser process + js execution. also, read other replies

  • @syntaxerorr
    @syntaxerorr Před 3 lety +1

    interesting video. Thanks.

  • @phutureproof
    @phutureproof Před 5 měsíci +1

    The older I get in my career and life the less I want to attempt to flex my ignorance, sure Ive heard C++ is fast and I've heard JS can be slow, but as this video shows there is always going to be some situation where that is marginalised, or really not that important, and I wont look like an utter bellend by keeping my gob shut.
    Simon, you are a gift to us mortal coders looking to expand our knowledge, thanks so much.

    • @simondev758
      @simondev758  Před 5 měsíci +1

      Same, as I get older, it's really just whatever works for the situation I'm facing.

    • @phutureproof
      @phutureproof Před 5 měsíci

      @@simondev758 I'm hoping to grab your teachable pack on payday, I really enjoy how you talk about stuff, very calm. All the best 👍

  • @nowpro4604
    @nowpro4604 Před 3 lety +2

    Love your videos, great effort. Chapters would be nice if you were to skip the coding part or something

  • @ArquimedesOfficial
    @ArquimedesOfficial Před 3 lety +27

    One time i was on mac donalds and a bunch of kiddos comes and asked for "One Big Mac full with javascript and pickles" LOL.

    • @APsupportsTerrorism
      @APsupportsTerrorism Před 3 lety +3

      Did you tell them the big mac isn't picklable?
      I'll get me coat ...

  • @d-one-and-only
    @d-one-and-only Před 2 lety

    really cool..... what are your thoughts about web assembly?

  • @exopolity
    @exopolity Před 3 lety +1

    What you think about Rust (webassembly) with JS. Maybe some tests? Do you have any experience? It is good idea to connect this two technology in work? For example In React App ...

    • @simondev758
      @simondev758  Před 3 lety

      I really want to try Rust out, but no haven't had the chance yet.

  • @goonholiday656
    @goonholiday656 Před 3 lety +4

    Me as a JavaScript developer trying to understand what you said: “Yes”

  • @dealloc
    @dealloc Před 3 lety +3

    Can highly recommend reading "Is WebAssembly magic performance pixie dust?" by Surma (a Web Advocate at Google). The article goes over compiling different languages (C, Rust, AssemblyScript) to WASM vs. idiomatic implementations in JS and running them in V8.
    It goes over some of the optimizations that V8 applies to JS and WASM through their compiler chain (there's a lot going on) and how in some cases JS can be much faster (and require less bundle size) than its WASM counterpart (without WASM bindings or Emscripten).

  • @astrahcat1212
    @astrahcat1212 Před rokem +2

    First thing to do in programming is access files locally and manipulate data.
    Without that I feel locked out.

  • @gilmoretj
    @gilmoretj Před 3 lety +2

    Hi, I think it might be interesting to compare the performance of C++ against WebAssembly.

  • @tmvkrpxl0135
    @tmvkrpxl0135 Před 3 lety +2

    Could you enable auto generated subtitle? I am student learning English and I need it to understand it properly

  • @crimson750
    @crimson750 Před 3 lety +27

    this guys voice is really soothing

    • @kevinjohansson3923
      @kevinjohansson3923 Před 3 lety +2

      Yeah, it's very very nice to listen to. Especially in today's overly expressive, borderline manic state most CZcamsrs present themselves in.

    • @wooooooongs
      @wooooooongs Před 3 lety

      that’s simple

  • @DevlogBill
    @DevlogBill Před 2 lety

    Keep creating video's using JavaScript, I enjoy your video's and I am pretty sure I am not the only one.

  • @Taurdil
    @Taurdil Před 3 lety +1

    How much more memory JS versions were allocating you said? It has to be a part of the comparison, right?

    • @simondev758
      @simondev758  Před 3 lety

      I need to investigate memory usage in a follow-up.

  • @ozzyfromspace
    @ozzyfromspace Před 3 lety +8

    Its not about how fast it is. It's about how you use it. Or something like that 😅😌🤓🏆

  • @colourfultoreador8467
    @colourfultoreador8467 Před 3 lety +31

    Javascript is fast for a high-level coding language

    • @illford6921
      @illford6921 Před 3 lety

      @Вероника Заглотова but do you want to learn lisp, as a student I looked for languages, saw lisp and then avoided it. It seems a bit too time consuming and hard to learn. I'd rather learn Assembly because at least that's funny

    • @tomm.4447
      @tomm.4447 Před 3 lety

      @Вероника Заглотова ((((((((((())))())))))))))

    • @jeremycoleman827
      @jeremycoleman827 Před 2 lety

      Lol +1

  • @halofreak644
    @halofreak644 Před 3 lety +1

    I'm getting into javascript but your knowledge as inspired me to go harder

  • @mayuukhupadhyay6845
    @mayuukhupadhyay6845 Před rokem

    Hello...
    Could you please tell me the user of backtick in javascript.. I've seen few places where inside backtick: c programming codes are written..

  • @rafaelmorales1926
    @rafaelmorales1926 Před 3 lety +2

    Oh god I noticed your voice is somewhat similar to Creed Batton and now I can't unhear it

    • @simondev758
      @simondev758  Před 3 lety +2

      Man, someone said it sounded like H Jon Benjamin, now I'm binge watching Archer. I might have to watch the office next.

  • @finnvictorsson
    @finnvictorsson Před 3 lety +2

    Your voice is relaxing

  • @nerdion1911
    @nerdion1911 Před 3 lety +1

    It would be really great if you compare NodeJS ES7/8 using async and C++ using async

  • @BlaBlupBlaa
    @BlaBlupBlaa Před 3 lety

    Did you try running the C++ code using modern C++ standard, e.g. containers (vectors, maps, lists, stack, etc), or shared_ptr instead of raw pointer? Using more modern methods (C++14 and upwards) may introduce overhead for the sake of readability that may or may not worsen the C++ result

    • @simondev758
      @simondev758  Před 3 lety

      Some modern stuff, was mostly straightforward.

  • @Cyberfoxxy
    @Cyberfoxxy Před 3 lety +4

    I think in C++ you can do performance optimizations that is simply impossible to do in JS. But then again, you rarely need that kind of performance. "Well what if you wanna update a million actors". Firstly, you don't, secondly: Batching, caching and only rendering nearby node (which you'd do anyway). Most the demands reside in physics and rendering.
    Just as a funny thought, i wonder if you can somehow perform calculations with CSS?

    • @simondev758
      @simondev758  Před 3 lety

      I actually have no idea what you can/can't do in css.

    • @okie9025
      @okie9025 Před 3 lety +1

      you can use the calc() function in CSS, but I doubt it's any better than just doing it in JS

  • @AmxCsifier
    @AmxCsifier Před 3 lety +3

    SimonDev: How
    Google: How old is queen Elizabeth
    *94 Years*

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

    In most modern applications, performance is typically IO bound. All programs inherently do three things -- read in data, process data, and output data. Modern machines are typically so far that the only parts you typically see an improvement is the middle section. If it takes five seconds to reach a SQL query and two seconds for something to render a graph on a screen, you typically have a (relative) lifetime in most cases to process the data before a user is going to notice something. Even JavaScript running on a browser typically spends 90% of it's time in an input loop. Whether it takes 30ms or 300ms to process the data probably won't be recognized.
    It takes some pretty specific applications these days before processing performance is really key. In most cases, you are better off optimizing the I/O, then your data structure/algorithm, etc. before having to look at a compiled language. Even then, such systems are typically on a knife's edge and you need to be considering hardware and other solutions. If an app needs to run five or ten times faster to be usable, you now have issues about older machines, other tasks running, etc. anyway.

  • @manin4568
    @manin4568 Před 3 lety +1

    Genius 👌👌

  • @jhyland87
    @jhyland87 Před 3 lety +5

    I use to always hate coding in JS, because I liked doing the backend stuff and JS was mainly just the UI/UX stuff. But then NodeJS came out and now I love coding in it. I actually just got a job offer as a Sr. Full Stack Developer for NodeJS/MongoDB/AngularJS/etc at a bank. Pretty excited :-)

    • @A1rPun
      @A1rPun Před 3 lety +2

      Good luck on that offer my fellow coder!

    • @jhyland87
      @jhyland87 Před 3 lety +4

      @@A1rPun thanks bud! Pending on the bg check - which makes me nervous... I have a colorful background and banks are strict. But I was an InfoSec engineer at PayPal and passed that bg check, so this should be ok.... Hopefully.

  • @indycinema
    @indycinema Před 3 lety +3

    Those comments were so unnecessarily aggro and miss the point that JS is what Web Devs already know and content on game patterns in C++ is already plentiful. It's helpful to see JS used using C++ idioms, instead of the framework nonsense that pervades webdev.

    • @simondev758
      @simondev758  Před 3 lety

      Pretty sure most of them were jokes, except for the middle one. But that one was great in its own way, so much anger heh. Loved it.

    • @kallehalvarsson5808
      @kallehalvarsson5808 Před 3 lety

      Not to mention the most obvious point - if you want to have a game that can run in the browser, then it's not like C++ is even an option.
      Either way, i always assumed that he used JS because of how forgiving and easy to read it is, which lends itself well to tutorials.

    • @DudeBronkster
      @DudeBronkster Před 3 lety

      @@kallehalvarsson5808 With web assembly, running C++ (or any other language that supports it as a compile target) in the browser is definitely an option. Many of the popular off the shelf game engines nowadays export to browsers, and they mostly compile to web assembly, not JavaScript.

    • @kallehalvarsson5808
      @kallehalvarsson5808 Před 3 lety

      @@DudeBronkster That is true, though last i worked with WASM, the support in some browsers (mainly Safari and Edge) was dodgy at best, maybe that has improved by now. But yes, you are perfectly right.

  • @chair547
    @chair547 Před 3 lety +1

    One thing people Miss is that when it comes to optimization your code doesn't need to be as optimize as possible it needs to be optimized enough. What that means depends entirely on your circumstances. Sometimes JavaScript is too slow and you do need to go to C or even assembly. But sometimes is not all times and usually JavaScript is good enough

  • @onkarkotkar8294
    @onkarkotkar8294 Před rokem +1

    Ty I’m getting a computer soon and I’m gonna use

  • @MrNispen
    @MrNispen Před 3 lety +4

    Im wondering if it would make a difference if you would run the code with nodejs instead of in the browser

    • @Soremwar
      @Soremwar Před 3 lety +3

      There are differences, but they are not that noticeable
      V8 is present in Chrome, Node and Deno. All of them optimize the operations between them and V8 to reduce the time in between, and that is how things in Deno for example are faster than in Node when using built-in APIs, but the same speed when running for loops
      I don't think any of the examples here would be faster in Node really, except perhaps the WebGL integration, I'd expect the browser to be faster there since that API is provided directly by them where as in Node, it's a third party library

    • @simondev758
      @simondev758  Před 3 lety

      I've done absolutely no research, but I'd guess that Steven is right in that it probably doesn't make a world of difference.

    • @tossajalumen401
      @tossajalumen401 Před 3 lety

      i think this would be really interesting to see is there any difference between nodeJS and browser. What i tested by my self, i was getting totally different results, but i'm not a master of this kind of testing :D

    • @MrNispen
      @MrNispen Před 3 lety +1

      The reason I thought it could be different is that Nodejs is a application itself, while javascript in the browser runs sandboxed within another application. Also in the browser you run the javascript in 1 tab, and the browser is designed to (possibly) run alot of tabs at once, so maybe the resources per tab could be limited.

  • @ToothlessXDIn
    @ToothlessXDIn Před 3 lety +3

    JavaScript speed is awesome even though it's interpreted(and/or JIT). It can't beat c++, because c++ code converted native to its hardware. But, That doesn't make c++ universally accepted for everything. JavaScript has its uses, c++/c has their own. Part of JavaScript slowness because of its running along side in browser thread(browser has to do a lot in own aside from interpreting JavaScript. Ex DOM manipulation, user interaction, data transfer, session, security etc).

    • @simondev758
      @simondev758  Před 3 lety +2

      JS is actually converted native to the hardware too, that's what the JIT does :) But the resulting code isn't quite as performant as what you get out of the box from c++. You're right though, they're different tools for different situations.
      But when I wanna just whip something together or test out some ideas, JS is there for me. It's like using premixed ingredients vs making dinner from scratch.

    • @softwarelivre2389
      @softwarelivre2389 Před 2 lety

      @@simondev758 yeah, running in the browser can cause some overhead. Running in Deno might yield better results. Not by much, of course, but probably slightly better. Might be worth testing.

  • @ponchietto
    @ponchietto Před 3 lety

    I can submit a real life example of a complex code written in C++ and ported to Javascript. It's a 3d mesh compression algorithm 'Corto' (on github), similar to Draco (from Google).
    Developed with focus on speed (without vectorization), and I can confirm a ~x2 factor in speed. The most important things (as in your video) was using BufferArrays.

    • @simondev758
      @simondev758  Před 3 lety

      That's awesome, happy to know other results are roughly in line.

  • @boudyhesham5875
    @boudyhesham5875 Před 3 lety +1

    simon i've graduated from computer science but i don't know about each data structure and arrays performance so i'm trying to improve myself and make a better version of me as a programmer, where can i learn about this to optimize my code and become a better programmer like you ?, thanks in advance

    • @simondev758
      @simondev758  Před 3 lety +1

      Plenty of resources online, just takes time.

  • @mechap7612
    @mechap7612 Před 3 lety +3

    Member functions defined in the class declaration are implicitely inlined

  • @28maitreyagupta21
    @28maitreyagupta21 Před 3 lety +3

    I see Silicon Valley on Recomendation(Jin Yiang):-"Ah I see a man of culture.".

  • @imalol1
    @imalol1 Před 3 lety +1

    Pretty interesting video!
    Would be interesting to compare I/O performance as well. :)
    As someone who works with Java extensively now I want to compare it to your results, might try it out on my free time.
    PS! Would be interesting to see the numbers for graalVM + javascript. I wonder if that would close the gap.

    • @simondev758
      @simondev758  Před 3 lety

      I'm not familiar with graalVM, from google it looks like it's a Java VM not JavaScript?

    • @imalol1
      @imalol1 Před 3 lety +1

      ​@@simondev758 There is support for js :) github.com/oracle/graaljs
      Though, now that I'm thinking about it I'm not sure how insightful this comparison would be since you would be just comparing one runtime to another. :P

    • @simondev758
      @simondev758  Před 3 lety +1

      Ah neat, missed that!

    • @jeremycoleman827
      @jeremycoleman827 Před 2 lety

      One of the early v8 engineers did a lot of work on graalvm. Graal is cool u can use python js and r all in the same file using template literals and it just compiles.

  • @sunstar8893
    @sunstar8893 Před 3 lety +1

    You sound like death the perfect amount for this video. I love it.

    • @simondev758
      @simondev758  Před 3 lety +1

      I may have to print that quote out for my office.