Ad
  • Custom User Avatar

    You are right. Here are benchmark results

    Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
    SumIntervalsOLogN 448.8 ns 8.97 ns 24.40 ns 0.2270 - - 712 B
    SumIntervalsMySolutionLinq 11,551.8 ns 32.93 ns 27.49 ns 4.0741 - - 12,824 B
    SumIntervalsMySolutionNoLinq 11,761.9 ns 225.21 ns 439.26 ns 0.7172 - - 2,296 B
    SumIntervalsCleverest 12,455.4 ns 247.32 ns 681.19 ns 2.7924 - - 8,776 B
  • Custom User Avatar

    Indeed. Here are results, where The cleverest - the first. My - third in this compilation.

    Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
    SumIntervalsOLogN 448.8 ns 8.97 ns 24.40 ns 0.2270 - - 712 B
    SumIntervalsMySolutionLinq 11,551.8 ns 32.93 ns 27.49 ns 4.0741 - - 12,824 B
    SumIntervalsMySolutionNoLinq 11,761.9 ns 225.21 ns 439.26 ns 0.7172 - - 2,296 B
    SumIntervalsCleverest 12,455.4 ns 247.32 ns 681.19 ns 2.7924 - - 8,776 B
  • Custom User Avatar

    I did it the same way. I think this should be a little bit faster than suggested the most clever solution