|
| 1 | +#:sdk Microsoft.NET.Sdk |
| 2 | +#:property TargetFramework=net10.0 |
| 3 | +#:project ../../src/SortAlgorithm |
| 4 | +using SortAlgorithm.Algorithms; |
| 5 | +using SortAlgorithm.Contexts; |
| 6 | + |
| 7 | +foreach (var n in new[] { 10, 20, 50, 100 }) |
| 8 | +{ |
| 9 | + Console.WriteLine($"=== n={n} ==="); |
| 10 | + |
| 11 | + // Sorted |
| 12 | + { |
| 13 | + var stats = new StatisticsContext(); |
| 14 | + var sorted = Enumerable.Range(0, n).ToArray(); |
| 15 | + FlatStableSort.Sort(sorted.AsSpan(), stats); |
| 16 | + Console.WriteLine($" Sorted : Compares={stats.CompareCount}, Writes={stats.IndexWriteCount}, Reads={stats.IndexReadCount}, Swaps={stats.SwapCount}"); |
| 17 | + } |
| 18 | + |
| 19 | + // Reversed |
| 20 | + { |
| 21 | + var stats = new StatisticsContext(); |
| 22 | + var reversed = Enumerable.Range(0, n).Reverse().ToArray(); |
| 23 | + FlatStableSort.Sort(reversed.AsSpan(), stats); |
| 24 | + Console.WriteLine($" Reversed : Compares={stats.CompareCount}, Writes={stats.IndexWriteCount}, Reads={stats.IndexReadCount}, Swaps={stats.SwapCount}"); |
| 25 | + } |
| 26 | + |
| 27 | + // Random (multiple runs) |
| 28 | + for (var seed = 0; seed < 3; seed++) |
| 29 | + { |
| 30 | + var stats = new StatisticsContext(); |
| 31 | + var random = Enumerable.Range(0, n).OrderBy(_ => seed * 1000 + Guid.NewGuid().GetHashCode()).ToArray(); |
| 32 | + FlatStableSort.Sort(random.AsSpan(), stats); |
| 33 | + Console.WriteLine($" Random{seed} : Compares={stats.CompareCount}, Writes={stats.IndexWriteCount}, Reads={stats.IndexReadCount}, Swaps={stats.SwapCount}"); |
| 34 | + } |
| 35 | +} |
0 commit comments