Skip to content

Add benchmark for UTF-8 decoding #1493

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 3 commits into from
Mar 2, 2016
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
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set(SWIFT_BENCH_MODULES
single-source/SuperChars
single-source/TwoSum
single-source/TypeFlood
single-source/UTF8Decode
single-source/Walsh
single-source/XorLoop
)
Expand Down
37 changes: 37 additions & 0 deletions benchmark/single-source/UTF8Decode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===--- UTF8Decode.swift -------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import TestsUtils

@inline(never)
public func run_UTF8Decode(N: Int) {
// 1-byte sequences
// This test case is the longest as it's the most perfomance sensitive.
let ascii = "Swift is a multi-paradigm, compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code (\"safer\") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program."
// 2-byte sequences
let russian = "Ру́сский язы́к один из восточнославянских языков, национальный язык русского народа."
// 3-byte sequences
let japanese = "日本語(にほんご、にっぽんご)は、主に日本国内や日本人同士の間で使われている言語である。"
// 4-byte sequences
// Most commonly emoji, which are usually mixed with other text.
let emoji = "Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭."

let strings = [ ascii, russian, japanese, emoji ].map { Array($0.utf8) }

for _ in 1...1000*N {
for string in strings {
var generator = string.generate()
var utf8 = UTF8()
while !utf8.decode(&generator).isEmptyInput() { }
}
}
}
2 changes: 2 additions & 0 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import StringWalk
import SuperChars
import TwoSum
import TypeFlood
import UTF8Decode
import Walsh
import XorLoop

Expand Down Expand Up @@ -171,6 +172,7 @@ precommitTests = [
"SuperChars": run_SuperChars,
"TwoSum": run_TwoSum,
"TypeFlood": run_TypeFlood,
"UTF8Decode": run_UTF8Decode,
"Walsh": run_Walsh,
"XorLoop": run_XorLoop,
]
Expand Down