E00: Software Drag Racing: C++ vs C# vs Python - Which Will Win?

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 มิ.ย. 2024
  • Retired Microsoft Engineer Davepl writes the same 'Primes' benchmark in Python, C#, and C++ and then compares and explains the differences in the code before racing them head to head to see what the performance difference is like between the languages.
    It appears the upload process does some volume leveling or loudness, so my apologies if you get startled during the into. It was mixed down in the master, honest :-)
    Thanks to the Simpsons for the inevitable reference or two that I throw in now and then! See if you can spot both in this episode!
    0:00 Start
    2:08 The Primes Assignment
    6:25 How a Sieve Works
    7:32 Coding Begins
    9:00 Python Version
    12:50 C# Version
    18:25 C++ Version
    22:22 Charts and Graphs
    23:17 Outtakes
    I've placed the code up on GitHub for your reference without any warranty for any purpose!
    github.com/PlummersSoftwareLL...
    I get a lot of questions about which keyboard I'm using as well as various other camera and studio equipment questions, so here are the highlights:
    CORSAIR K70 RGB MK.2 Mechanical Gaming Keyboard (Cherry MX Blue Switches)
    amzn.to/31UrUUD
    Sony FX3 or A7SIII Cameras
    amzn.to/31TRdWK
    amzn.to/3wG9iG7
    Aputure 120D Mark II Light and Light Dome II Mini
    amzn.to/3uya8Ts
    amzn.to/31XwBx2
    Glide Gear TMP100 Prompter
    amzn.to/3ux84Ll

ความคิดเห็น • 2.7K

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

    Best video I have watched in a long time.

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

      Yes for sure, he brings some inspiration :-)

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

      time to redo this

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

      Bad@$$ Studio, 🎤 🎙 with your 🧰 Toolbox & LEDs Projects🎉❤

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

      22:45 Please No More "FANCY " @$$ GRAPHS 😅😅

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

    A cool project would be to set up a git repo for everyone to check in their implementations of this algorithm in their favourite language. Then set up a CI pipeline to run them every time someone commits an optimisation. Chart the results.

    • @gianluca.g
      @gianluca.g 3 ปีที่แล้ว +33

      Nice! Reminds me of the fire routine speed challenge

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

      That would be Hella cool

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

      Time to rewriting everything everything in Rust again...

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

      People will write platform specific assembly code in C++ to optimize the code. But then it doesn't work on another hardware platform..... so it's kinda useless. X86 has alot alot of very specialized operations that can speed things up hundreds of times. But it will not work on another cpu.

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

      @@HermanWillems does that make it any less interesting of an exercise? It might make it even more fragmented and difficult in being able to set up appropriate CI pipelines, but I still think it’d be interesting.
      Aside from that, you could forbid dropping down to assembly if you felt that to be cheating.

  • @spotlight-kyd
    @spotlight-kyd 3 ปีที่แล้ว +252

    When writing tight loops in Python, you have to remember two things about the language:
    1. Attribute lookups and variable lookups not in the local namespace are slow.
    2. Calling functions is slow.
    Thus I was able to speed up the Python version in the repo from 39 iterations for limit 1_000_000 to ~150 iterations just by inlining the code from GetBits/ClearBits and creating a reference for this.rawbits and this.sieveSize in local variables (and by eliminating the superfluous check for index%2 in the inner loop).
    This speedup is achieved without any optimizations to the algorithm.

    • @mrroryc
      @mrroryc ปีที่แล้ว +19

      Spot on - generating the function preamble is maybe 20 cycles or more (on x86 anyway)
      Also - keep loop conditions as simple as possible (check line 139 of the CPP)
      But the point of the video really is that in Python or any interpreted language - writing lazy code will cost you exponentially more execution time

    • @aouerfelli
      @aouerfelli ปีที่แล้ว +1

      @@mrroryc What is lazy code?
      And, what do you mean by "exponentially"?

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

      @@aouerfelli hi there - when I say "lazy code", I mean, not taking the time to do things properly and obey the basic rules of good programming practice. Be nice to the compiler (or interpreter) and it will be nice to you :)
      As for "exponentially" - I was referring to the inherent overhead of Python being an interpreted language coupled with "lazy code", will make your code exponentially slower.
      The trade off here is supposed to be readability and ease of use - but it comes at a VERY large cost.

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

      Oh and btw - for line 139 - implementing that as a "do while" rather than a "while" and performing the calculation in the loop would give the compiler a better chance of optimizing it ....
      Which leads me to a question - what compiler optimization level were you using Dave? Could make a huge difference....

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

      Be weary that you may have different hardware which would impact your results.

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

    Reminds me of a similar comparison that Google did a decade ago. It got kind of ridiculous when the Java engineers went "We can do better than 30% of C performance, we just need to hand-tune the VM and allocation settings!"

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

    His HS CS class: Algorithm optimization competition with classmates
    My HS CS class: Creating seemingly never ending popup dialogs that ultimately climax with "You Suck"

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

      Ha! It was a great class... but I've been in the one you describe too I think :-)

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

      At least you had CS in HS. I had to learn it in College.

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

      It was Visual Basic. The class was called "Computer Applications 2" (Apps 1 was Excel, Access and PP). The teacher had learned that in theory every shuffle of the old card game Freecell is beatable. So she was on a mission to beat all 62,000 (or whatever it is) possible games.
      Basically we just learned from our books. We would quickly make whatever Fahrenheit to Celsius converter, or pizza topping chooser thing we had to do for class. Then we'd just screw around and do dumb stuff.

    • @markp5726
      @markp5726 3 ปีที่แล้ว

      About the only thing I remember of my hs prog class is that we used 15 year old apple ][ computers. The teacher may've been good at geometry but not so much at programming. His robotics class was more interesting but he still caused people to drop the class on day 1 😣

    • @KipRoof
      @KipRoof 3 ปีที่แล้ว

      @@markp5726 We used Apple ]['s as well but they were brand new! And the students were still generally better at programming than the teachers.

  • @luischinchilla-garcia4840
    @luischinchilla-garcia4840 3 ปีที่แล้ว +659

    Incredible comparison!
    I'd also like to add how -- this man has successfully managed to write the most C++ looking script in Python 😂

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

      ikr, I was looking at that and thought "is this really python? this guy probably doesn't even know that there is a built-in function to get the length of an array!"
      Actually, while learning C++ arrays, I had to look up how to get a length of an array, and was unpleasantly surprised to find that there is no built-in way to do that.

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

      @@bluesillybeard std::array has both size() and max_size() as well as the ability to call std::size(array). std::size also works on old style c arrays (e.g. int x[])which I assume is what you were looking at but std::size only entered the standard fairly recently (c++17). Tricky thing about c++ is there are a lot of out of date answers that say it can't do things, or has to do things in gross ways, that there are much better ways of doing it now.

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

      @@flamingmonky111 good to know, thanks!

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

      I looked for this comment earlier. Yes, I had to do a double take at that Python. :D

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

      @@bluesillybeard I have to learn c++ for work. Ive mostly used java and python. im scared lol

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

    The C++ STL does actually have a bit array! It is just unfortunately called std::vector. Seriously, the standard says this specialization of vector should be implemented as an array of bits!

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

      all STL is just bad if you can avoid it you better do that.

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

      @@vaualbus this opinion is so tired and old. I work in high performance systems, and we don't avoid the std. More often than not it's better than developing your own solutions or pulling in third party code. We have a very small selection of custom containers and algorithms and use the std mostly everywhere else. Vendors these days are pretty good at keeping things lean.

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

      I was under the impression that the bool type was one byte

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

      @@KleptomaniacJames It may, or may not, be, but here @juvenal1228 wanted a bit array, not a byte array!

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

      Let us then use the RtlInitializeBitMap() and friends from ntdll !

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

    Massive respect for the systematic and clear approach to this comparison (the experience you gathered over the years is very clearly showing in the methodology and explanation).
    Instant subscribe! Thanks for this and keep up the great work!

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

    As someone who gets pumped following along to a free code academy tutorial video for Python. I am awe struck by this persons career and his ability to explain it to someone like myself. Keep rocking it!

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

    I rarely see well-executed language comparisons. I love these performance/comparison types of videos.
    I really enjoyed it, thank you!

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

    We are about same age, i have enjoyed many of your videos because the products were so important in my career. Its good to put a human face on the digital world and see a programmer who worked on the product.

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

    I noticed in his comments that Dave's reasoning for using std:out was to avoid printing new lines with Python's build in print function, but there's actually an easier way to do it.
    When calling the print function you can customize the endline character by using, well, endline="whatever you want as endline" as a parameter.
    That way, your endline character could be a comma followed by a space, or whatever else you needed.
    Other than that small tidbit which I came across by chance, awesome job as always Dave.

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

    Beyond the "Hello World" program in C64 basic 30+ years ago, I'm not a coder. So it's a testament to your presentation style that I can more or less follow what you're doing, and enjoy watching the show. Keep it up!

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

      I would hope your C64 version of Hello World was the evergreen:
      10 PRINT "HELLO WORD"
      20 GOTO 10
      RUN
      ;)

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

      I started out with Atari Basic. It actually wasn't an interpreted language but would compile to P-Code when a line was entered and when run, it ran the P-Code with a software engine.

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

    Although there were no surprises, it is a great video. Many Python programmers knows that the best way to achieve performance in Python is not using Python. This means that you should do most of the computation calling C optimized libraries like numpy, tensorflow, sklearn.

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

      But those are still python IMHO. The power of python is to be a glue language like that!

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

      @@retrolabo yes it still python but C/C++ will do the heavy work for it, python just need a wrapper to call them, and most of language can make a wrapper to call to C/C++ function

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

      @@nguyentranminhquang2861 yes this is what I mean by glue language. This is a strange distinction: think about it "print" in python is written in C in the interpreter, does this make the print function not python? :)

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

      Using numpy or pandas to implement a sieve is the equivalent of robbing a bank with an atom bomb.

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

      @@BrunodeSouzaLino you need to win a race, whatever it takes lol... wait a minute who said we cannot use a GPU for that? :P

  • @ian.e.mccormick
    @ian.e.mccormick 3 ปีที่แล้ว +228

    Best original Content on TH-cam right now. Killing the Game Dave!!!

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

      Thanks! Tell a friend! :-)

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

      @@DavesGarage my buddy Ian McCormick just called me and told me I had to check out this video.
      Very cool but maybe we can throw Golang and/or Rust into the mix. I'm incredibly interested to know what an OG C engineer thinks of Go vs Rust (vs C and/or C++)

    • @trevc63
      @trevc63 3 ปีที่แล้ว

      Agreed!

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

    I LOVE your channel. I learn so much by watching you. Thank you!

  • @KadeDev
    @KadeDev 3 ปีที่แล้ว

    this is such a sick video. I love this channel now, its so cool to get these comparisons.

  • @pihi42
    @pihi42 ปีที่แล้ว +28

    There are optimizsations you can do even on assembly level. Like using fancy vector instructions and such. I once optimized a piece of C++ code with some embedded assembly instructions to gain 10x performance just using MMX on a Pentium chip. Usually the hard part is identifying which 0.1% of code really needs to be optimized.

    • @dale116dot7
      @dale116dot7 ปีที่แล้ว +5

      I’ve had one embedded application that needed to be 100% rewritten in assembly language. The compiled C code was about six times as large as the assembly language version, and the assembly language version used all but 15 bytes of 60k of flash memory. No larger memory versions of the processor were available. The C code was not anywhere close to fitting in the given processor. I think it took me about a month and a half to write the whole application in assembly.

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

      All the major C++ compilers vectorise if optimisation is turned on.

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

    This is so awesome sir! I really really wonder how come I didn't find your channel so far!

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

    This was wild, and mind blowing. I correctly guessed the order, but the speed of the code is what really floored me. Thanks for the demo, walking us through it briefly, and for displaying the code as well.

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

    Would love to see them run on the M1 and ARM on a Pi4

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

      Mee too.

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

      Would also love to see them run on Sparc 64 and MIPS

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

      Oh, I didn't even think of the raspberry PI. If Dave needs one, I can send him a PI to have so he can do this test. I have a few laying around.

    • @space_0027
      @space_0027 3 ปีที่แล้ว

      Me too

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

      Cool, I will add for the Pi3 and Pi4 if I get a moment!

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

    This line here: `for (int num = factor * 3; num

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

      That can make a significant difference on the larger tests. Take for example, factor =709. Using factor * 3 means you’ll start at 2,127, while factor ^2 will start at 494,209, removing 353 unnecessary calls to test/clear that bit from that innermost loop. And that’s testing just one of 168 prime factors less than 1,000 (which is what would be used looking for primes less than 1M). The amount of unnecessary loops skipped by his change scales exponentially with the upper limit of primes you’re looking for.
      This will be almost unmeasurable on the smaller tests. Such as primes up to 10,000.

    • @jackgerberuae
      @jackgerberuae 2 ปีที่แล้ว

      Note this

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

      Additionally, above factor = 3, you can instead of 'for(int num=factor; num < sieveSize; num++)' write 'num += 6', and have two if-statements, one for "getBit(num - 1)" and second for "getBit(num + 1)", since all primes except 2 & 3 can be written as "p = 6k +- 1"

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

    This was awesome. Thanks for the explanation. It's interesting to see how far we've come. I started on TRS-80 basic.

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

    Very cool, Dave. Thanks for the great content. It strikes a nice balance between educational and entertaining. Beauty

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

    Thank you for that Simpsons reference. I’ve literally been doing that voice for 20 some odd years!

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

      You and me both :-)

  • @algorithminc.8850
    @algorithminc.8850 3 ปีที่แล้ว +9

    Really great channel and video - and fun presentation. And a fair language comparison, I'd say. We've been developing in straight C since the late 80's ... and have "secure/portable" libraries for just about everything. The modern compilers are amazing at yielding reasonable machine code (no need to spend so much time on assembly, aside for maybe some hardware specialties). We wrap our C with whatever language does the job for the client or product development. Some of those higher-level languages might be useful these days for people learning how coding works ... kind of like assembly language and BASIC may have been for us. So great finding your channel ... subscribed and telling friends ... cheers ...

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

    First time I've ever subscribed to a channel after just one video. This was great!

    • @DavesGarage
      @DavesGarage  3 ปีที่แล้ว

      Welcome aboard! Thanks for joining!

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

    Thank you for taking me back to the Commodore Pet. Our highschool didn’t have any computers when I started, but in the 4th year they started showing up in shops, and I was one of the “regulars” using the demo model. Eventually a TRS-80 model 1 was bought to help staff plan classes, (Dutch schooling allows you to select a subset of classes for 4th to 6th year, so they have to juggle schedules to ensure optimal planning.) I was then the “gang-leader” of those allowed to use it for the rest of the year. Exciting times.

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

    These programming videos have been some of my favorites you've done! Please do the M1!

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

    The first 30 seconds of this earned you a subscription

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

    I loved your charismatic way of explaining the technical details. I was able to pull out a little bit more efficient (codewise) Python version while using the same algorithm you taught us, but still, the performance gap is astounding, I read there are many people here in the comment section sharing their viewpoint about a better Python implementation as if Dave was trying to undervalue Python, remember, this is a kind of "syntetic test" and depending on the Context it might be more reasonable to use one or the other of the languages.

  • @mirozen_
    @mirozen_ ปีที่แล้ว +1

    Nice to see good stuff from another former Blue Badge!!! Just found your channel and I'm enjoying your stuff! 😊👍

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

    As a retired CPU designer, I am constantly surprised by the "discovery" that interpreted languages (even those that use a JIT) are so much slower than optimized C or even assembly. There is little appreciation for the massive overhead of many of these script-like languages. As a demonstration to convince a software developer that we could run their massive program on a $35 compute module I recoded their most critical routine in assembly (60 instructions long) and showed that their entire system ran with less than 10% of a very cheap machine rather than 40% of a Mac.
    The real nightmare, however, is the strato-layering of "packages" one on top of another instead for minimal additional functionality but a perceived decrease in design time. These chew up CPU cycles in massive overhead damaging the responsiveness and size of the code generated. As CS schools have stopped teaching even the rudiments of computer architecture this is not likely to change. Great for CPU producers, but a massive waste in time, power, and cost.

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

      @randy You discovered the secret of Forth. Forth allows easy replacement of a single bottle neck.

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

      @@albertmagician8613 Yeah, but I could not force myself to always work off a stack.... RPN on an HP calculator was great but for general purpose programming?!?
      I think it would be a great video to show how to profile some code and optimize the slowest pieces for better performance. That's effectively what I ended up doing and it makes a huge difference for any sort of interactive code, such as CAD tools.

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

      Yes. It's a revolting waste...

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

      Why do you think CS programs have stopped teaching such things? I graduated relatively recently and my average rated US school required two courses on embedded design, one on assembly language, and one computer design which focused on the specifics of logic gates, ALUs, etc. I suspect you're trying to strengthen your position by creating a strawman argument. I think at best you could demonstrate that the worst programs don't teach these things but that was likely always true.

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

      @@nonconsensualopinion I have no need of a strawman as I'm not arguing, but stating an observation. Some programs do indeed require traditional logic and some architecture classes, but increasingly those are being phased out as more emphasis is placed on web programming and large variety of dialects available for layering systems. I could give a list of such programs but it's not my point. Deep layering and package-based design are making systems increasingly inefficient. The good news is that I think we're headed for more actions like the one I stated in my original post, but slowly. I also think it's a massive opportunity as server and system costs can be reduced through breaking down software layers.

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

    In C++ you have the bitset class and can create a bitset of 1 million bits. And the other even faster method and more memory efficient is to create a vector.
    C++ is king.

    • @jplflyer
      @jplflyer 3 ปีที่แล้ว

      Wouldn't the vector allocate a byte per boolean? So that's not memory efficient, which was one of his criteria.

    • @DrunkenUFOPilot
      @DrunkenUFOPilot 3 ปีที่แล้ว

      @@jplflyer Nope. STL defines a special case just for vector. Sometimes you really want a vector of actual bool type values, whether that's a byte or the same size as int, but good luck defining it due to this special case. What if you want to define a reference to some Nth bool in a vector? There is no reference to a bit in C++.

  • @paulchoudhury2573
    @paulchoudhury2573 2 ปีที่แล้ว

    Excellent treatment of this topic. The only suggested follow up I would have is some discussion of why 64 bit turns out to be much faster than 32 bit and if the C# implementation uses 64 bit "under the hood". Keep them coming Dave, you've got a new fan!

  • @bassbatterer
    @bassbatterer 3 ปีที่แล้ว

    Nice video, that story at the beginning really rung brought back some memories.

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

    Since you asked, here some things about your Python code that I haven't seen commented here yet:
    • print() has a keyword argument for specifying the character(s) added to the end of the line, so for example you can do print("Hello, world", end="") to avoid printing
    at the end of the line.
    • From what I've seen, its convention to use all-lowercase snake_case for variables and function names, and CamelCase for class names (though the stdlib doesn't always respect that)
    • You don't need the parentheses on your if statements

    • @n-steam
      @n-steam 3 ปีที่แล้ว +5

      tbf naming conventions aren't language specific, they're programmer specific.

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

    Wow! Loving C# more every day!
    Just looking at Python for a project using Raspberry Pi, and have to say, it's a dog. I'm about the same age as the presenter, so his language experience really resonated with me.
    Great video! Wish I could up-vote more than once. Thanks! 👍👏👏👏

    • @alanmusicman3385
      @alanmusicman3385 ปีที่แล้ว +1

      For ex-BASIC coders like myself C# is an ideal halfway house to C++. Learn C# and learn Powershell and you can address most programmic needs. Never as fast as C++ of course, but a lot less cryptic and most times it catches you when you fall and gives you a decent diagonistic message.

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

    Awesome video, eh. Loved it--definitely a new subscriber here. Thanks for your efforts Dave!

    • @DavesGarage
      @DavesGarage  3 ปีที่แล้ว

      Thanks and welcome aboard!

  • @AtlantaTerry
    @AtlantaTerry 3 ปีที่แล้ว

    Dave, very nice production values: camera, lighting and sound.

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

    Respect, that's all I can say other than I am impressed. I also am very happy, C++ has been my go to language for a long time. Keep these videos coming. The prime number program was one that we were required to code in my algorithms college course, also one that I found difficult was a program to estimate pi to a given decimal place(this was user defined at runtime). Ugh, we were forced to write that one in of all languages basic. Yes the professor would allow only basic for that one. I had a sadistic algorithms professor I suppose. He allowed me to use C for the prime number program though so can't complain too much. Love the video and will be watching your others in the future.

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

    std::vector is size optimized for something like a "dynamic bitset"

  • @UNIVLOCATEFUN
    @UNIVLOCATEFUN 3 ปีที่แล้ว

    Excellent video, keep it up. Intend to watch you a lot going forward.

  • @Taras195
    @Taras195 3 ปีที่แล้ว

    I just stumbled upon your video, and subbed! Great explaination and interesting stories!

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

    Amazing video. Btw would highly recommend taking a look at other python interpreters like pypy, to librarires like numba, or to cython. The last two options will impact the flexibility that made me love python but the results are totally worth it. Especially cython.

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

    Omg... This is going to be soooo awesome 😎.
    I already decided my religious and no changeable attitude towards all these platforms, but damn it'll be fun to either be right or rectified :p
    More content like this... It's getting really geeky 👾

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

    top notch and super easy to follow video. helped me a lot

  • @xpwn3rx
    @xpwn3rx ปีที่แล้ว +1

    Dave, your breakdown of how some of this works is very interesting to me. I'm a Server and Storage Architect and team manager, and I have a BS is Computer Information Systems. By the time I was learning in the mid to late 00's, they didn't teach about bitarrays or any of the way the assembly works, we just learned OO languages like Java, C#, J#, and of course I've done some python dabbling since. I prefer C# but getting a peak behind the covers from someone who understands the assembly behind the scenes was interesting.

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

    This is such a great channel.

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

    Python is "compiled" into bytecode too (usually saved as .pyc files), but the bytecode interpreter is really just that. So no overhead for parsing, but no optimizations either, that's why it's slow when doing compurational intensive tasks (for which often times you just use optimized packaged/libraries). There are versions of python that jit this bytecode to increase raw performance, e.g. pypy.
    Running on my old laptop, I get 42 Passes from your Python Program when run in CPython (what most people use as "Python"). Simply switching the Interpreter to pypy I get 561 Passes from the exact same source file.

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

      Another reason why Python code is slower than C code is dynamic typing. Even when JIT compiling, the compiler needs to add checks that the types of the variables are still what the JIT compiler believes them to be. Same for array bounds checks.

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

      That's not what "compiled" means. That's simply syntax tokenized reduction. It's been around since the days of BASIC.

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

      ​@@mihiguy That's interesting. It seems when we re-write the Python code can be statically typed (eg; compilers like Cython, Numba, ect... all implement their own type systems) it would remove all that.

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

      @@knowlen For JavaScript, that is what asm.js is doing. Expect a restricted, strongly typed subset of JavaScript and compile directly to machine code. However, this has mostly been obsoleted by WebAssembly.

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

      Python is just the "Flavor-of-month" at one time it was Javascript. C++ is closer to the "metal" and you have a dozens of toolkits for optimization.

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

    It's been years since I have written code, but having cut my teeth on c, I was curious. Your experiment did not disappoint.
    Recently, I have been playing with arm, so when you mentioned the M1, it peeked my interest.
    If you run it, I will watch.

  • @aaronfulkerson1151
    @aaronfulkerson1151 3 ปีที่แล้ว

    My coworkers and I are very interested in seeing this same benchmark on an M1 and also with Node since you included PHP in your repo. Great video!

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

    The 64-bit result is shocking; I'd of never thought you'd get that much of a delta over 32-bit!

    • @MI08SK
      @MI08SK 10 หลายเดือนก่อน +1

      64-bit supports some game changing new instructions witch can be used to optimise a program

    • @arithex
      @arithex 9 หลายเดือนก่อน +1

      The x64 calling convention is much simpler .. first few args are passed in registers, akin to __fastcall in MS VC++. And there are a lot more registers, which means less juggling values to/from the stack frame, and it also allows for more aggressive function-inlining by the compiler.
      Also also, compiling for x64 is like an implicit hint to the compiler, "this is a modern CPU so you can use all the new SSE etc instructions.. don't have to worry about compat with a 20 year old Pentium"

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

    Some comments on the Cpp version:
    1. There's a native bit array, it's just called "std::vector". It's slightly horrible that it's a specialization of vector, but it does work and does what you expect.
    2. The std::chrono default aliases (seconds, milliseconds etc) are all specified with integers as the base type, for compile-time safety. If you want fractional time amounts, you can define your own alias, e.g.
    using dseconds = std::chrono::duration;
    And now you can duration_cast to that, without having to fiddle with getting it in microseconds and then multiplying by a million to get more resolution.

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

    In C++ there is std::vector which actually is implemented as 1 bit per element, though it likely would be slower.

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

    Enjoyed the story. I took some time to work on an implementation in R and got some pretty good performance out of it. Major take-away: understanding what is REALLY going on in a programming language can allow us to write clean code. As I tell my Grad students: first get it RIGHT, then make it BETTER.

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

    And here I struggled with iterative loops and abstract classes within my 6 months C# crash course learning lol, the amount of knowledge you must posses is truly astonishing.

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

    Believe it or not, I wrote a prime number generator in dBase IV. It saved the prime numbers in the database. When I packed up at the end of the day, I left it running on the IBM AT overnight. Since the prime numbers were in a database, it could pick up where it left off the previous morning. The database was handy for factoring huge numbers.

  • @5cover
    @5cover 3 ปีที่แล้ว

    Very interesting vidéo as always!

  • @che1602
    @che1602 3 ปีที่แล้ว

    Oh my, I love the style. Should’ve checked you out long ago. Instant sub!

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

    As a little advice : to compare a value with either 'True' or 'False', use 'is' instead of '=='. Python will compare the objects' id directly and it's the most optimized way to do it.

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

      Better yet, don‘t compare with True or False altogether, i.e.:
      if this.getBit(num):
      pass

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

      @@anonanon3066 Python is a real language.

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

      @@anonanon3066 that makes you sound like you're not a real programmer

    • @TBaguette
      @TBaguette 3 ปีที่แล้ว

      @@philipmunch3547 I agree, this is even better, but I have not coded in Python for a long time, I've been more into Rust recently.

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

      Yup, do not do this. Never compare against True or False using is, unless there are other "truthy" or "falsy" values that are anticipated, e.g. use of None as a placeholder, canary, or NULL equivalent. Identity comparisons may seem to operate the way you expect (True and False being literal singletons in CPython), however other situations will be far stranger. 27 is 27 → True. Some larger numbers that end up not being interred will not have this identity match, a similar problem with using this to compare strings for equality.
      Philip Münch has it right. Just use the "if" statement itself as the mechanism of casting and boolean comparison. The right tool for the job. Combined with "exit early" patterns, my special case of using None should be accounted for first, then the remainder of the function exited from if needed, so that the subsequent truthy or falsy comparison doesn't worry about None at all.
      In JS there is the paradigm of double-inversion to cast to a boolean, e.g. !!foo, Python simply does not have this silly need.

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

    Implementing that same prime number generator in a new language is a fantastic idea, I'll try out something similar next time!

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

      someone do a java2k version please!

    • @JannisAdmek
      @JannisAdmek 3 ปีที่แล้ว

      @@derkeksinator17 omg ok, I'll put it on github should I succeed, but that's rough

    • @pantoqwerty
      @pantoqwerty 3 ปีที่แล้ว

      @@JannisAdmek Has anyone tried it in Rust? Seems to be the language everyone wants to talk about these days. Be interesting to see what, if any, hit there is. Also be more interested in time for n cycles rather than cycles in t time.

  • @El.Duder-ino
    @El.Duder-ino 2 ปีที่แล้ว

    Wow, thank you for making this comparison - even I am not a programmer I really do enjoy understanding why code performs better in comparison to other language... but I do agree, if you get lowest you can get and optimize it to the limit, its the best you can achieve.

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

    I've never heard of you before now. That intro was legendary. I'm building a breadboard computer this year.

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

      I've never heard of you either, but I'd be interested in hearing more about the breadboard computer, what kind, what CPU, etc!

    • @muninnsmith7958
      @muninnsmith7958 3 ปีที่แล้ว

      @@DavesGarage I'm not entirely sure. 🤔 I was inspired by Ben Eater. I'll keep you updated.

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

    From Australia, keep these coming.

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

    In C#, have you compiled it in release mode? For me, this increased the benchmark value from ~1900 to ~5000. Also, updating it to .NET 5 improved the performance on my machine by another 2% to ~5100.

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

      Yeah it looks like its set to Release mode; I was looking for the same thing. I got similar results switching from Debug to Release, plus the X2 performance from 32bit to 64bit. Very eye opening.

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

      @@DOSdaze If you compile the c# project to x86 only, the speed drops from ~5000 to ~4500 on my machine.

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

      @@vonBlankenburgLP Interesting, I wonder whats making the significant difference for me. In release mode 64bit I'm getting around 4900 passes every run, but then drops down to 2800 in 32bit very consistently. I'm on an 8700K clocked at 4.4GHZ running Windows 10.

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

      Can confirm, I'm getting ~5300 when running the C# code in release mode on my 3700X, which in theory should be slower than Dave's 3970X. The C++ code is reasonably close with ~7300. Seems to me that something is wrong with his C# test.

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

      @@moki5796 My guess is he's a C++ guy?😋 just kidding. Interesting though but we all know C++ is faster sooo..... C# is my fav language, C++ is great too. I'm going to get hate for this but every time I use Python I just feel like something is missing and it bugs me but I can't put my finger on it. I get the popularity and it's used by around 8 Million people but I'm guessing at least 50% are noobs, where as around 6Million use C# and am guessing less than 10% will be noobs...sooo...don't know never tried IronPython maybe that will peak/solidify my interest?

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

    What a cool comparison! I learned something too. I recently started learning Julia, so I copied the program more or less to test the advertised speed of Julia. For 1 million upper limit, I got 4228 passes in 10 seconds, an average of 2.3 milliseconds. I was quite astonished! This is comparable to C# and C++.

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

    You look like the Chuck Norris of coders. I am even more amazed by you clear and understandable explanation than by the performance differencess. Would have been interesting to see the java and java script performance - just to finally end all those performance discussions.

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

    You can probably speed up the Python code Cythoning some of it (Cython is still Python, well... Sort of...). Great video and excellent test!

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

    Hey Dave, love the videos keep doing them. I was wondering if you have thought of making a discord server for your community at all since I would love to be able to find more discord servers to discuss coding and help new people learn to code and you channel seems to suit that. Much love from your fellow Sask resident

  • @tshandy1
    @tshandy1 3 ปีที่แล้ว

    This was an excellent video, and you are fantastic teacher. I use C# in my daily job, and for what we are doing, its performance is acceptable. But the capabilities of C++, as you have demonstrated, are amazing.

    • @DavesGarage
      @DavesGarage  3 ปีที่แล้ว

      Glad it was helpful!

  • @marvinabt4964
    @marvinabt4964 ปีที่แล้ว +1

    I mean C++ techincally has vector for dynamic bitarrays. I believe it uses size_t instead of 8-bit chunks, because it's made to dynamically change size even after being created. I know technically alot of people don't like it in bigger codebases for various reasons, but in isolation it works fine just to access and change bits.

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

      Wanted to suggest the same. It is actually not specified how it needs to be implemented, it is not even required that it allocates 1/8th of the memory of `vector`. And I agree having a specialization for `vector` is indeed a mess, since it technically not fulfilling the requirements of `std::vector`, such as having the elements stored as-if they were in a plain C-array.

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

    Sometimes compilers and interpreters are surprising! I wrote a Monte Carlo simulation in VBA under Excel, coded as creating and destroying objects for each simulated item. Then recoded it to do all the memory allocation. and deallocation on a static array and it ran at near enough exactly the same speed! That OO stuff was implemented well!

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

      or the other stuff really bad.
      main mistake was using vba and excel ;)

    • @Richardincancale
      @Richardincancale 3 ปีที่แล้ว

      @@stke1982 Well sometimes you have to do what the client wants! I’ve written MC simulations in a variety of languages from Fortran IV onwards! My point was that the hand crafted stack operation version was indistinguishable in performance from the OO version - to my surprise.

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

    For python, what I managed to catch: self instead of this, index//2 instead of int(index/2), use if __name__ == '__main__' for mains, so in case you import the code elsewhere it doesn't run the main, you do not need to retype something as a string in a print, also prettier way is to use f strings, you can use **.5 instead of sqrt, but this is more optional, than previous tips. Also for the sieve, you can actually start with square multiple, instead of 3rd multiple. That was all I caught, happy coding

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

      f strings are not only prettier but also faster, since they don't require an expensive function call

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

      There are also a number of loops that could be optimized.
      Generally speaking, in Python for-loops are faster than while-loops, and often more so, list comprehensions are even faster than for-loops. In code like this with possibly many iterations you can often see a very significant performance (and sometimes memory usage) improvement when switching to list comprehensions. Plus when you are used to using them list comprehensions are often more readable.
      You can go even further with the functools module and using "pure" functions that avoid side-effects (save calls to print or log to places outside the pure functions). This approach can lead to much more readable and succinct code.

    • @MultiTsunamiX
      @MultiTsunamiX 3 ปีที่แล้ว

      @@pjkirkham yeah. I saw some of those but since i did not had the code, I didnt want to tell him about it. But you Are correct

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

    Thank you for showing me a baseline - how does a really passionate programmer are look like. Huge difference from many other TH-cam participants. No society related talks. Just the code and figuring out things using code.

  • @henny022
    @henny022 3 ปีที่แล้ว

    In C++ there is vector which depending on your standard library implementation is optimized for using a bitarray and takes a size at runtime.
    also a runtime comparrison between bit arrays and byte arrays might be interesting

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

    Using Python's abstractions tends to be faster than trying more low-level optimizations. That's because for many of these Python is able to optimize stuff using lower level tools that are not accessible to the user, like C bindings. JS also performs quite a lot of optimizations at the engine level. If you could somehow implement the sieve using numeric methods, you could use something like Numpy and you'd be essentially running C behind the scenes.

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

    You should add golang and rust into the mix

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

      I like to watch that

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

      And maybe Java

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

      @@SulemanAsghargoion _All of them_

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

      and the fastest scripting language: LuaJIT

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

      @@August0Moura This would actually be really interesting, luajit is really quite fast

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

    If only I could be such an expert... I'm just blown away. With coding each time I stop and think I'm somewhat not bad at it, then each and every time it is happening, I see someone who makes me feel like I know nothing...

  • @PierreThierryKPH
    @PierreThierryKPH 2 ปีที่แล้ว

    I was hooked by Pascal's wager at the end. I subscribed. :-)

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

    Great video! Just want to point out that most python devs wouldn’t try to do something like that in native python. We’d either use a library like numpy or build one in c. Python is really more of a scripting language, I use it to call other bits of code in a readable sort of way. Once you learn/build the main packages that are relevant to your job, it’s crazy how fast you can push out code, which might not be 100% as fast as C, but it’s fast enough and very easy to maintain.

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

      fast enough is kind of relative, isn't it ? I mean, his code ran close to ten thousand times faster in C++/64 compared to Python 😂
      I remember writing a small snippet of code a few weeks back just to count from 1 to a billion I think on C, Python, VB, and MATLAB, and I remember the code was much, much slower in Python than C, though not that much slower if memory serves.

    • @tomwalker996
      @tomwalker996 ปีที่แล้ว +1

      @@MoodyG That's the thing. In real life there would never be a requirement to "count to 1 billion". But I would create a dataframe in Pandas that contained the positive integers from 1 to 1 x 10^9. If you're doing that kind of thing in native Python, you're doing it wrong.

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

      @@tomwalker996 I think you totally missed the point. Of course you wouldn't wanna count to a billion in real life. It just serves as a simple example to illustrate the comparative difference in speed between different languages. Counting up to a billion is way, way more trivial a task than what you'd actually wanna do in real life. An actual useful code for some real-life application may very well end up eating through computations many orders of magnitude more than a billion primitive addition operations.

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

    Yep very interested to see it tested on other chips, especially the M1. Now I'm curious about how Rust will perform as well as something functional like F#

    • @HermanWillems
      @HermanWillems 3 ปีที่แล้ว

      In Rust we will then write a module that will call special cpu specific optimalisations and beat F# the fuck out of the water. That's what's so nice about system programming languages. They can go deep into the cpu while bytecode languages cannot do that so easily.

  •  3 ปีที่แล้ว

    This is very entertaining; you're doing this at exactly the pace I prefer. Looking forward to the follow up of this with more languages.

  • @alk99875
    @alk99875 3 ปีที่แล้ว

    just saw 1 minute but you are good man, well done, keep up

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

    Hey man, you could use the numpy lib for Python to run functions like "sqrt" even faster. Python wasn't really made with speed in mind but numpy was. Many of numpy's functions were writting in C to make it performant. I would like to think that's the reason why Python is used in Machine Learing - numpy + other C libs for Python (speed) + python (Minimal code, readability). Loved you video!

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

    Basically me watching this channel: i like your funny word, magic man

    • @VredesbyrdNoir
      @VredesbyrdNoir 2 ปีที่แล้ว

      Hahaha, Clone High reference?

  • @TheGadusi
    @TheGadusi 3 ปีที่แล้ว

    Love your presentations.

  • @zaphodbeebs961
    @zaphodbeebs961 3 หลายเดือนก่อน

    Great video. Very instructional. Thank you.

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

    I like benchmarks too. I converted the C# version to PHP.
    CPU: i7-2600k
    - 5sec of iterations
    Python 3.8.5: 23 passes
    PHP v7.4.3: 50 passes
    C# .NETCore 3.1 compiled with VS 2019: 1623 passes

    • @xBINARYGODx
      @xBINARYGODx 10 หลายเดือนก่อน +1

      * rolls eyes *

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

    this guys videos are very well put together there are very few cuts. I hate how youtube is full of cuts

  • @Whatthetrash
    @Whatthetrash 2 ปีที่แล้ว

    Fantastic episode! ^_^

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

    Cool! I got into coding on programmable calculators (TI-57). A buddy and I would compete to see who could write the same projects within the limited memory constraints of the calculator, and with the least number of steps. It was a great way to learn by trying different methods of coding to reduce the step count. Later I went on to become a telecommunications engineer and he went on to become a hard core programmer from assembly up. He would write code, then compile and link, in different languages, and benchmark sections of each by counting clock cycles, and would often rewrite the problem parts in assembly code to speed things up (he specialized in optimizing video drivers). These days I design and build test systems that have to communicate with other equipment that have different response characteristics so to help optimize the code I put timer marks that I can turn off and on at startup that help me find the bottlenecks. It would seem this is a lot of work for a little slice of time but since the code runs thousands and thousands of time every day, those little slices add up to a lot of time by the end of a year worth of testing. That said, your Software Drag Race video should be the poster child of software development for anybody running code in a high volume production environment. Thank you sir!

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

    I really like your pointing out that the algorithm can greatly affect the run time. Back in the 8080 days, I had a TRS-80 computer. Basically a 1Mhz Z-80 chip. I wrote a poor algorithm in assembler and a smart one in interpreted BASIC. The BASIC code ran faster.
    I don't code much anymore. I'm pretty much maintaining an obsolete system, which will be retired soon, followed by me. Now, I mainly game on a console. I can feel my brain rotting.

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

    honestly I really enjoyed this comparison. It was so in-depth and fun and I really liked the anectode. Also, Dave's diction and oration skills are so good, like ??? the way he speaks is so engrossing
    **BIG shoutout to Dave's python code using this instead of self. If Guido didn't want us using the **correct** keyword for the current instance, he should not have made it customizable**

  • @AJKvideoproductions
    @AJKvideoproductions 3 ปีที่แล้ว

    Awesome video Dave :D

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

      Thanks! 😀. Sequel coming soon!

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

    Great video! Thanks. But two questions regarding Python. Or maybe they are the same, so please forgive me as I'm still new to programming. What about unlocking the GIL? And what about Cython? I'm just wondering how it would affect the results, or even if it could be used for these functions. I'd love to hear your thoughts on this topic.

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

    Would be interesting to do this with C and gcc as well and see if the compiler makes a huge difference between. Also keeping track of the results as a bitmap is a great space savings, but is it really a time saving? With a modern system you could store everything in a byte array, or even an integer array.

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

      Yeah, the bitmap seems like a downgrade. On the 64-bit compiler, an int64 is probably the fastest array type (I'm guessing.)
      However, the point is to establish relative performance between different platforms, so perhaps super-optimization is less important than using the same code on multiple machines. Actually, come to think of it, that's the best possible reason to skip the bitmap array, since some platforms may have trouble with it.

    • @tiagodagostini
      @tiagodagostini ปีที่แล้ว +5

      Space saving helps speed in modern CPUS because it increases cache coehrence.

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

    Yes, please do the M1 Mac!

  • @mpiloz8016
    @mpiloz8016 11 หลายเดือนก่อน

    this was an interesting one, I'm gonna rewatch it after my python exam in a few hours.

  • @jorgeferreira6727
    @jorgeferreira6727 3 ปีที่แล้ว

    Very interesting video. The story about coding in the eighties, just brought to memory some of my own adventures of that time.
    My biggest was to use a ZX-Spectrum as a cross development platform for the intel MCS-86 test board. It was quite an adventure but saved me countless journeys by train and bus to the Uni campus.
    Back to today.
    I think the main difference between the C++ 32bits and 64bits is the better usage of the hardware. The 64 bit compilation is probably making more extensive use of the vector processing hardware, as in AVX2.
    The difference between C++ and C# is not a surprise, but is bigger than I expected.