Collection.sortInPlace() => .sort()

This commit is contained in:
Dmitri Gribenko
2015-11-15 21:03:01 -08:00
committed by Max Moiseev
parent 8f7c9ae3fd
commit 77376883f4
8 changed files with 34 additions and 34 deletions

View File

@@ -203,20 +203,20 @@ Algorithm.test("sorted/complexity") {
// Check performance of sorting an array of repeating values.
var comparisons_100 = 0
ary = [Int](repeating: 0, length: 100)
ary.sortInPlace { comparisons_100++; return $0 < $1 }
ary.sort { comparisons_100++; return $0 < $1 }
var comparisons_1000 = 0
ary = [Int](repeating: 0, length: 1000)
ary.sortInPlace { comparisons_1000++; return $0 < $1 }
ary.sort { comparisons_1000++; return $0 < $1 }
expectTrue(comparisons_1000/comparisons_100 < 20)
// Try to construct 'bad' case for quicksort, on which the algorithm
// goes quadratic.
comparisons_100 = 0
ary = makeQSortKiller(100)
ary.sortInPlace { comparisons_100++; return $0 < $1 }
ary.sort { comparisons_100++; return $0 < $1 }
comparisons_1000 = 0
ary = makeQSortKiller(1000)
ary.sortInPlace { comparisons_1000++; return $0 < $1 }
ary.sort { comparisons_1000++; return $0 < $1 }
expectTrue(comparisons_1000/comparisons_100 < 20)
}