Skip to content

Commit 6a5fc12

Browse files
Add benchmark for UTF-8 decoding
1 parent fc1735c commit 6a5fc12

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(SWIFT_BENCH_MODULES
8585
single-source/SuperChars
8686
single-source/TwoSum
8787
single-source/TypeFlood
88+
single-source/UTF8Decode
8889
single-source/Walsh
8990
single-source/XorLoop
9091
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===--- UTF8Decode.swift -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
@inline(never)
16+
public func run_UTF8Decode(N: Int) {
17+
// Use test data with UTF-8 sequences of all lengths, but mainly ASCII.
18+
let string = "Mainly ASCII but also some 2-byte sequences (пример),"
19+
+ " some 3-bytes sequences (성능 테스트) and occasionally a 🐼 (4 bytes)"
20+
let data = Array(string.utf8)
21+
for _ in 1...N {
22+
var generator = data.generate()
23+
var utf8 = UTF8()
24+
while !utf8.decode(&generator).isEmptyInput() { }
25+
}
26+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import StringWalk
9090
import SuperChars
9191
import TwoSum
9292
import TypeFlood
93+
import UTF8Decode
9394
import Walsh
9495
import XorLoop
9596

@@ -171,6 +172,7 @@ precommitTests = [
171172
"SuperChars": run_SuperChars,
172173
"TwoSum": run_TwoSum,
173174
"TypeFlood": run_TypeFlood,
175+
"UTF8Decode": run_UTF8Decode,
174176
"Walsh": run_Walsh,
175177
"XorLoop": run_XorLoop,
176178
]

0 commit comments

Comments
 (0)