Skip Navigation

What are you time crunching right now?

I made a mistake in my dates and so I have a few chapters to edit and upload and I have work tomorrow morning. Gonna be rough.

So, to make myself feel better, what are you time crunching this week?

29

You're viewing part of a thread.

Show Context
29 comments
  • Personally I'm just a hobbiest, I'm not really fluent in anything. I want to hack together a (extremely simple) OS. I'd imagine C++ is close to the effiency of Rust, no?

    • C++ is a superset of c, and isn't inherently slower. It just has a ton of bells and whistles that were trendy in the 90s such as OOP abstractions.

      You could say that a c++ amateur programmer will tend to write more resource intensive code than an amateur c programmer due to wanting to use the abstractions.

      Take for instance a level with 10k animals in it such as ducks and dogs. Ducks and dogs have their own Update implementation. A world Update function has to update all the animals.

      In c++ you will naturally be inclined to use polymorphism by creating an animal class and letting the duck and the dog classes inherit from it. You have a single list with 10k animals. The duck and dog classes override the animal's Update method with their own implementation. The world Update function uses a loop to call the Update method on all 10k animals.

      What you might not realize is that under the hood the computer has to do a lookup in a function table for each animal. Both the duck and the dog classes have their own virtual tables that the CPU has to go through to find the actual implementation of their respective Update function.

      Now in C, you'd be inclined to simply create two separate sets, one for dogs and one for ducks. You'd loop over each one individually.

      There are no lookups for the CPU to do here. It just applies the same Update function to a large set of structured dog or duck data.

      Now, the performance impact won't matter in most cases. You could even write it in python and it'll be way slower but at least your code will be readable. But now imagine 10mln or 10bln animals. It's going to make a difference.

      Rust on the other hand is in the same class of performance as C.

You've viewed 29 comments.