mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Collection.sortInPlace() => .sort()
This commit is contained in:
committed by
Max Moiseev
parent
8f7c9ae3fd
commit
77376883f4
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user