Why is D significantly slower than C# in this instance?
H. S. Teoh
hsteoh at qfbox.info
Mon Apr 10 21:40:40 UTC 2023
On Mon, Apr 10, 2023 at 09:18:59PM +0000, Artjom via Digitalmars-d wrote:
> I have written this simple bruteforce algorithm that finds max sum of
> subsequence in some sequence, both in C# and D. And when the size of
> array is 1000000 elements - D is 20 seconds lated. Why?
Which compiler are you using and what are the compiler options?
> D code (algorithm):
> '
> public int solveBruteForce()
> {
> int currMax = arr[0], currSum;
> foreach (_; arr)
> {
> currSum = 0;
> foreach (int el; arr)
> {
> currSum += el;
> currMax = max(currSum, currMax);
> }
> }
>
> return currMax;
> }
> '
> D code (measuring exec time):
> '
> double measureTime()
> {
> StopWatch sw;
> sw.start();
> solveDynamic();
This doesn't call the above function solveBruteForce. What's the
definition of solveDynamic?
> double sec = (to!double(sw.peek.total!"msecs") / 1000) +
> (to!double(sw.peek.total!"usecs") / 1000000);
> return sec;
> }
[...]
T
--
Two wrongs don't make a right; but three rights do make a left...
More information about the Digitalmars-d
mailing list