Why is D significantly slower than C# in this instance?
WebFreak001
d.forum at webfreak.org
Wed Apr 12 12:19:12 UTC 2023
On Monday, 10 April 2023 at 21:29:11 UTC, Artjom wrote:
> [...]
>> D code (measuring exec time):
> ```
> double measureTime()
> {
> StopWatch sw;
> sw.start();
> solveDynamic();
> double sec = (to!double(sw.peek.total!"msecs") / 1000) +
> (to!double(sw.peek.total!"usecs") / 1000000);
> return sec;
> }
> ```
> [...]
the logic here is wrong, `.total!"..."` already sums the
different units, you can just do `sw.peek.total!"hnsecs" /
10_000_000.0` to get the total seconds as double.
Otherwise this currently always doubled the time, since you added
the total (converted) seconds twice.
More information about the Digitalmars-d
mailing list