I wonder how fast we'd do
Uknown
sireeshkodali1 at gmail.com
Tue May 28 05:20:14 UTC 2019
On Tuesday, 28 May 2019 at 04:38:32 UTC, Andrei Alexandrescu
wrote:
> https://jackmott.github.io/programming/2016/07/22/making-obvious-fast.html
I tested 3 D variants :
---ver1.d
double sum = 0.0;
for (int i = 0; i < values.length; i++)
{
double v = values[i] * values[i];
sum += v;
}
---ver2.d
double sum = 0.0;
foreach (v; values)
sum += v * v;
return sum;
---ver3.d
import std.algorithm : sum;
double[] squares;
squares[] = values[] * values[];
return squares.sum;
All 3 were the exact same with LDC. https://run.dlang.io/is/6pjEud
More information about the Digitalmars-d
mailing list