Why is D significantly slower than C# in this instance?
Walter Bright
newshound2 at digitalmars.com
Tue Apr 11 02:12:40 UTC 2023
On 4/10/2023 2:18 PM, Artjom 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?
>
> public int solveBruteForce()
> {
> int currMax = arr[0], currSum;
> foreach (_; arr)
> {
> currSum = 0;
> foreach (int el; arr)
> {
> currSum += el;
> currMax = max(currSum, currMax);
> }
> }
>
> return currMax;
> }
The outer loop does nothing, perhaps C# optimizes it away.
More information about the Digitalmars-d
mailing list