This is so true tho

  • vrek@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    2 hours ago

    There is a video where a real game dev was showing how bad a specific benchmark was. It was basically read arguments, get a random number, do a for loop 10,000 times, inside there do another for loop 10,000 times, do some equation with a modulo, put result in array, pick a number from array and print to screen.

    The biggest time cost was the modulo as that’s the hot path. He basically went through and typecast all the ints to double. He got 4x the speed. It went from almost 2 seconds to less than 0.5 second just on that change. This is mostly due to cpu and compiler now using simd instructions.

    Small changes can have big impacts.

    • palordrolap@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      41 minutes ago

      Yeah, I’ve actually written quick and dirty code that used both a division and a modulus, but then went back later to use the former to calculate the latter with a multiplication and a subtraction to get a speed improvement.

      There have been other occasions where I’ve been able to replace something like average = sum / count; if average > y with if sum > count * y, when it’s not entirely obvious that y could be multiplied by anything and remain meaningful.

      But when a division can’t be avoided, you still want that genius-written magical library to take some of the sting out of it.

      • vrek@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        31 minutes ago

        He didn’t do any of that. Just typecast the numbers to be doubles.

        The whole benchmark was a mess but that part specifically surprised me.