On Saturday, 20 May 2023 at 18:27:47 UTC, Ali Çehreli wrote:
[...]
And I've just discovered something.

Me2! The serial version using array indexing

   void vec_op_naive0 (double [] outp, const double [] inp,
      double function (double) fp)
   {
      enforce (inp.length == outp.length);
      auto i = inp.length;
      while (i--)
         outp [i] = fp (inp [i]);
   }

is nearly thrice as fast as the one using lockstep

   void vec_op (double [] outp, const double [] inp,
      double function (double) fp)
   {
      foreach (ref a, b; lockstep (outp, inp))
         a = fp (b);
   }

I wonder if under this circumstances (lack of speed, lack of parallelism out-of-the-box) it makes any sense to prefer lockstep over
the indexed array access.

Reply via email to