Skip to content

[benchmark] CheckResults with auto-generated error message #9330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions benchmark/single-source/CString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let reference = 517492

@inline(never)
public func run_CStringShortAscii(_ N: Int) {

func DoOneIter(_ arr: [String]) -> Int {
var r = 0
for n in arr {
Expand All @@ -79,11 +79,10 @@ public func run_CStringShortAscii(_ N: Int) {

var res = Int.max
for _ in 1...100*N {
let strings = input.map {
let strings = input.map {
$0.withCString(String.init(cString:))
}
res = res & DoOneIter(strings)
}
assert(res == reference)
CheckResults(res == reference)
}

1 change: 0 additions & 1 deletion benchmark/single-source/ObjectAllocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,3 @@ public func run_ObjectAllocation(_ N: Int) {
CheckResults(ListResult == 48375)
CheckResults(ArrayResult == 3000)
}

1 change: 0 additions & 1 deletion benchmark/single-source/SortLettersInPlace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ public func run_SortLettersInPlace(_ N: Int) {
CheckResults(letters[0].value <= letters[letters.count/2].value)
}
}

36 changes: 25 additions & 11 deletions benchmark/utils/TestsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,31 @@ public func Random() -> Int64 {
return lfsrRandomGenerator.randInt()
}

public func CheckResults(_ resultsMatch: Bool, _ message: @autoclosure () -> String) {
guard resultsMatch else {
print(message())
abort()
}
@inline(__always)
public func CheckResults(
_ resultsMatch: Bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: indenting in this file is two spaces.

file: StaticString = #file,
function: StaticString = #function,
line: Int = #line
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: closing paren here should be de-indented.

guard _fastPath(resultsMatch) else {
print("Incorrect result in \(function), \(file):\(line)")
abort()
}
}

// Due to potential overhead of passing closures around on the
// performance measurements, this version is now deprecated
@available(*, deprecated,
message: "For debugging test failures only! Use the version without message.")
public func CheckResults(
_ resultsMatch: Bool,
_ message: @autoclosure () -> String
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here.

guard resultsMatch else {
print(message())
abort()
}
}

public func False() -> Bool { return false }
Expand All @@ -71,9 +91,3 @@ public func someProtocolFactory() -> SomeProtocol { return MyStruct() }
// which are using it.
public func blackHole<T>(_ x: T) {
}

@inline(__always)
public func CheckResults(_ resultsMatch: Bool) {
guard _fastPath(resultsMatch) else { abort() }
}