Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ebe5aba
feat(collection): Replace quickSort with pdqsort for performance and …
abbashosseinii Nov 4, 2025
ea66e16
test(collection): add benchmark for pdqsort vs. baseline quickSort
abbashosseinii Nov 4, 2025
63fcfac
Merge branch 'main' into feature/replace-quicksort-with-pdqsort
abbashosseinii Nov 4, 2025
307ec48
docs(collection): add changelog for quickSort pdqsort enhancement
abbashosseinii Nov 5, 2025
009090e
refactor(core): Optimize and clarify _pdqSiftDown in heapsort
abbashosseinii Nov 5, 2025
3c80f38
docs(benchmark): Improve documentation clarity for BenchmarkResult class
abbashosseinii Nov 5, 2025
5c3d1ef
feat(benchmark): Add dataset generator and sorting benchmarks for qui…
abbashosseinii Nov 5, 2025
a6e53f9
chore: format code with `dart format`
abbashosseinii Nov 15, 2025
ec13079
refactor(algorithms): Remove unused imports and optimize _log2 function
abbashosseinii Nov 15, 2025
4073118
refactor(sort): Optimize `_pdqSort3` based on @lrhn's suggestion
abbashosseinii Nov 15, 2025
f530bae
refactor(benchmark): Replace `getNextList` method with a getter to fo…
abbashosseinii Nov 16, 2025
4a239f2
Update pkgs/collection/lib/src/algorithms.dart
abbashosseinii Nov 16, 2025
660314a
fix(dataset_generator): Adjust random dataset generation to use full …
abbashosseinii Nov 16, 2025
3b64a20
Refactor: Improve list generation in _generatePathological
abbashosseinii Nov 16, 2025
d5d4f52
Refactor: Improve list creation in _generateReverse
abbashosseinii Nov 16, 2025
6546d0c
Refactor: Improve list creation in _generateSorted
abbashosseinii Nov 16, 2025
5122e32
Refactor(benchmark): Pre-compute deterministic base lists
abbashosseinii Nov 16, 2025
cc7f09a
Chore: Use direct stepping in pathological list creation loops
abbashosseinii Nov 16, 2025
9ebe846
Chore: Use `.reversed` to create the reversed base list
abbashosseinii Nov 16, 2025
3960d63
Refactor: Improve clarity and correctness of benchmark data generators
abbashosseinii Nov 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/collection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Add `PriorityQueue.of` constructor and optimize adding many elements.
- Address diagnostics from `strict_top_level_inference`.
- Run `dart format` with the new style.
- Replace `quickSort` implementation with a more performant and robust
Pattern-defeating Quicksort (pdqsort) algorithm.

## 1.19.1

Expand Down
54 changes: 54 additions & 0 deletions pkgs/collection/benchmark/dataset_generator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Centralized generation of datasets for all benchmarks.
///
/// Ensures all algorithms are tested on the exact same data.
library;


import 'dart:math';

const size = 50000;
const count = 128; // Number of lists to cycle through.

final List<List<int>> random = _generateRandom();
final List<List<int>> sorted = _generateSorted();
final List<List<int>> reverse = _generateReverse();
final List<List<int>> fewUnique = _generateFewUnique();
final List<List<int>> pathological = _generatePathological();

List<List<int>> _generateRandom() {
final r = Random(12345);
return List.generate(
count, (_) => List.generate(size, (_) => r.nextInt(2000)));
}

List<List<int>> _generateSorted() {
final base = List.generate(size, (i) => i);
return List.generate(count, (_) => List<int>.from(base));
}

List<List<int>> _generateReverse() {
final base = List.generate(size, (i) => size - 1 - i);
return List.generate(count, (_) => List<int>.from(base));
}

List<List<int>> _generateFewUnique() {
final r = Random(67890);
return List.generate(count, (_) => List.generate(size, (_) => r.nextInt(7)));
}

List<List<int>> _generatePathological() {
final base = List.generate(size, (i) => i);
// Creates a "V-shape" or "organ pipe" array that can be challenging
// for quicksort implementations by promoting unbalanced partitions.
final pathological = <int>[
for (int i = 0; i < size; i++)
if (i.isEven) base[i],
for (int i = size - 1; i > 0; i--)
if (i.isOdd) base[i],
];
return List.generate(count, (_) => List<int>.from(pathological));
}
Loading