Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into unicode-rethink
- Loading branch information
Showing
654 changed files
with
10,296 additions
and
11,352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//===--- DropLast.swift ---------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import TestsUtils | ||
|
||
let reps = 1 | ||
let sequenceCount = 4096 | ||
let prefixCount = 1024 | ||
let dropCount = sequenceCount - prefixCount | ||
let sumCount = prefixCount * (prefixCount-1) / 2 | ||
|
||
@inline(never) | ||
public func run_DropLastCountableRange(_ N: Int) { | ||
let s = 0 ..< sequenceCount | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.dropLast(dropCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in DropLastCountableRange: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
fileprivate struct MySequence: Sequence { | ||
let range: CountableRange<Int> | ||
public func makeIterator() -> IndexingIterator<CountableRange<Int>> { | ||
return range.makeIterator() | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_DropLastSequence(_ N: Int) { | ||
let s = MySequence(range: 0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.dropLast(dropCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in DropLastSequence: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_DropLastAnySequence(_ N: Int) { | ||
let s = AnySequence(0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.dropLast(dropCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in DropLastAnySequence: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_DropLastArray(_ N: Int) { | ||
let s = Array(0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.dropLast(dropCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in DropLastArray: \(result) != \(sumCount)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===--- LazyFilter.swift -------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// This test checks performance of creating an array from lazily filtered | ||
// collections. | ||
import TestsUtils | ||
|
||
@inline(never) | ||
public func run_LazilyFilteredRange(_ N: Int) { | ||
var res = 123 | ||
let c = (1..<1_000_000).lazy.filter { $0 % 7 == 0 } | ||
for _ in 1...N { | ||
res += Array(c).count | ||
res -= Array(c).count | ||
} | ||
CheckResults(res == 123, "Wrong result in LazilyFilteredRange 123 != \(res)") | ||
} | ||
|
||
@inline(never) | ||
public func run_LazilyFilteredArrays(_ N: Int) { | ||
var res = 123 | ||
let c = (1..<1_000_000).map({[$0]}).lazy.filter { $0.first! % 7 == 0 } | ||
for _ in 1...N { | ||
res += Array(c).count | ||
res -= Array(c).count | ||
} | ||
CheckResults(res == 123, "Wrong result in LazilyFilteredArray 123 != \(res)") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//===--- Suffix.swift ---------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import TestsUtils | ||
|
||
let reps = 1 | ||
let sequenceCount = 4096 | ||
let suffixCount = 1024 | ||
let sumCount = suffixCount * (2 * sequenceCount - suffixCount - 1) / 2 | ||
|
||
@inline(never) | ||
public func run_SuffixCountableRange(_ N: Int) { | ||
let s = 0 ..< sequenceCount | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.suffix(suffixCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in SuffixCountableRange: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
fileprivate struct MySequence: Sequence { | ||
let range: CountableRange<Int> | ||
public func makeIterator() -> IndexingIterator<CountableRange<Int>> { | ||
return range.makeIterator() | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_SuffixSequence(_ N: Int) { | ||
let s = MySequence(range: 0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.suffix(suffixCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in SuffixSequence: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_SuffixAnySequence(_ N: Int) { | ||
let s = AnySequence(0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.suffix(suffixCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in SuffixAnySequence: \(result) != \(sumCount)") | ||
} | ||
} | ||
} | ||
|
||
@inline(never) | ||
public func run_SuffixArray(_ N: Int) { | ||
let s = Array(0 ..< sequenceCount) | ||
for _ in 1...20*N { | ||
for _ in 1...reps { | ||
var result = 0 | ||
for element in s.suffix(suffixCount) { | ||
result += element | ||
} | ||
CheckResults(result == sumCount, | ||
"IncorrectResults in SuffixArray: \(result) != \(sumCount)") | ||
} | ||
} | ||
} |
Oops, something went wrong.