• ebc@lemmy.ca
    link
    fedilink
    arrow-up
    15
    arrow-down
    1
    ·
    8 months ago

    A great point in favour of maps is that each iteration is independent, so could theoretically be executed in parallel. This heavily depends on the language implementation, though.

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        4
        arrow-down
        1
        ·
        8 months ago

        Imperative for loops have no guarantee at all that iterations could be executed in parallel.

        You can do some (usually expensive, and never complete) analysis to find some cases, but smart compilers tend to work the best the dumbest you need them to be. Having a loop that you can just blindly parallelize will some times lead to it being parallel in practice, while having a loop where a PhD knows how to decide if you can parallelize will lead to sequential programs in practice.

        • noli@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          8 months ago

          While you do have a fair point, I was referring to the case where one is basically implementing a map operation as a for loop.