Skip to content

Commit 69eb0f6

Browse files
Merge pull request #6879 from allevato/character-benchmarks
Add benchmarks for initializing Characters from literals.
2 parents 71d08b4 + 9c07eb6 commit 69eb0f6

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ set(SWIFT_BENCH_MODULES
3131
single-source/ByteSwap
3232
single-source/Calculator
3333
single-source/CaptureProp
34+
single-source/CharacterLiteralsLarge
35+
single-source/CharacterLiteralsSmall
3436
single-source/Chars
3537
single-source/ClassArrayGetter
3638
single-source/DeadArray
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- CharacterLiteralsLarge.swift -------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This test tests the performance of Characters initialized from literals
14+
// which don't fit into the small (63-bit) representation and need to allocate
15+
// and retain a StringBuffer.
16+
import TestsUtils
17+
18+
@inline(never)
19+
func makeCharacter_UTF8Length9() -> Character {
20+
return "a\u{0300}\u{0301}\u{0302}\u{0303}"
21+
}
22+
23+
@inline(never)
24+
func makeCharacter_UTF8Length10() -> Character {
25+
return "\u{00a9}\u{0300}\u{0301}\u{0302}\u{0303}"
26+
}
27+
28+
@inline(never)
29+
func makeCharacter_UTF8Length11() -> Character {
30+
return "a\u{0300}\u{0301}\u{0302}\u{0303}\u{0304}"
31+
}
32+
33+
@inline(never)
34+
func makeCharacter_UTF8Length12() -> Character {
35+
return "\u{00a9}\u{0300}\u{0301}\u{0302}\u{0303}\u{0304}"
36+
}
37+
38+
public func run_CharacterLiteralsLarge(_ N: Int) {
39+
for _ in 0...10000 * N {
40+
_ = makeCharacter_UTF8Length9()
41+
_ = makeCharacter_UTF8Length10()
42+
_ = makeCharacter_UTF8Length11()
43+
_ = makeCharacter_UTF8Length12()
44+
}
45+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//===--- CharacterLiteralsSmall.swift -------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This test tests the performance of Characters initialized from literals that
14+
// fit within the small (63 bits or fewer) representation and can be
15+
// represented as a packed integer.
16+
import TestsUtils
17+
18+
@inline(never)
19+
func makeCharacter_UTF8Length1() -> Character {
20+
return "a"
21+
}
22+
23+
@inline(never)
24+
func makeCharacter_UTF8Length2() -> Character {
25+
return "\u{00a9}"
26+
}
27+
28+
@inline(never)
29+
func makeCharacter_UTF8Length3() -> Character {
30+
return "a\u{0300}"
31+
}
32+
33+
@inline(never)
34+
func makeCharacter_UTF8Length4() -> Character {
35+
return "\u{00a9}\u{0300}"
36+
}
37+
38+
@inline(never)
39+
func makeCharacter_UTF8Length5() -> Character {
40+
return "a\u{0300}\u{0301}"
41+
}
42+
43+
@inline(never)
44+
func makeCharacter_UTF8Length6() -> Character {
45+
return "\u{00a9}\u{0300}\u{0301}"
46+
}
47+
48+
@inline(never)
49+
func makeCharacter_UTF8Length7() -> Character {
50+
return "a\u{0300}\u{0301}\u{0302}"
51+
}
52+
53+
@inline(never)
54+
func makeCharacter_UTF8Length8() -> Character {
55+
return "\u{00a9}\u{0300}\u{0301}\u{0302}"
56+
}
57+
58+
public func run_CharacterLiteralsSmall(_ N: Int) {
59+
for _ in 0...10000 * N {
60+
_ = makeCharacter_UTF8Length1()
61+
_ = makeCharacter_UTF8Length2()
62+
_ = makeCharacter_UTF8Length3()
63+
_ = makeCharacter_UTF8Length4()
64+
_ = makeCharacter_UTF8Length5()
65+
_ = makeCharacter_UTF8Length6()
66+
_ = makeCharacter_UTF8Length7()
67+
_ = makeCharacter_UTF8Length8()
68+
}
69+
}

benchmark/utils/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import BitCount
3636
import ByteSwap
3737
import Calculator
3838
import CaptureProp
39+
import CharacterLiteralsLarge
40+
import CharacterLiteralsSmall
3941
import Chars
4042
import ClassArrayGetter
4143
import DeadArray
@@ -139,6 +141,8 @@ precommitTests = [
139141
"ByteSwap": run_ByteSwap,
140142
"Calculator": run_Calculator,
141143
"CaptureProp": run_CaptureProp,
144+
"CharacterLiteralsLarge": run_CharacterLiteralsLarge,
145+
"CharacterLiteralsSmall": run_CharacterLiteralsSmall,
142146
"Chars": run_Chars,
143147
"ClassArrayGetter": run_ClassArrayGetter,
144148
"DeadArray": run_DeadArray,

0 commit comments

Comments
 (0)