Skip to content

Commit 0061d26

Browse files
committed
Measurements: NumberTests+Glyph.swift.
1 parent bba2ea8 commit 0061d26

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//=----------------------------------------------------------------------------=
2+
// This source file is part of the DiffableTextViews open source project.
3+
//
4+
// Copyright (c) 2022 Oscar Byström Ericsson
5+
// Licensed under Apache License, Version 2.0
6+
//
7+
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+
//=----------------------------------------------------------------------------=
9+
10+
#if DEBUG
11+
12+
import DiffableTestKit
13+
@testable import DiffableTextStylesXNumeric
14+
15+
//*============================================================================*
16+
// MARK: * NumberTests x Glyph
17+
//*============================================================================*
18+
19+
final class NumberTestsXGlyph: Tests {
20+
21+
//=------------------------------------------------------------------------=
22+
// MARK: State
23+
//=------------------------------------------------------------------------=
24+
25+
let iterations = 1
26+
let digits = [Digit](repeating: .seven, count: 1)
27+
28+
//=------------------------------------------------------------------------=
29+
// MARK: Tests
30+
//=------------------------------------------------------------------------=
31+
32+
/// 10,000 digits and 10,000 iterations: 10.137 seconds.
33+
func test_Digits_ForEachUnicodeScalar_String() {
34+
measure {
35+
var accumulator = String()
36+
accumulator.reserveCapacity(digits.count * iterations)
37+
//=--------------------------------------=
38+
// MARK: Append
39+
//=--------------------------------------=
40+
for _ in 0 ..< iterations {
41+
for digit in digits {
42+
digit.unicode.write(to: &accumulator)
43+
}
44+
}
45+
}
46+
}
47+
48+
/// 10,000 digits and 10,000 iterations: 0.030 seconds.
49+
func test_Digits_UnsafeBitCastToBytes_String() {
50+
measure {
51+
var accumulator = [UInt8]()
52+
accumulator.reserveCapacity(digits.count * iterations)
53+
//=--------------------------------------=
54+
// MARK: Append
55+
//=--------------------------------------=
56+
for _ in 0 ..< iterations {
57+
accumulator.append(contentsOf: unsafeBitCast(digits, to: [UInt8].self))
58+
}
59+
//=----------------------------------=
60+
// MARK: Result
61+
//=----------------------------------=
62+
let _ = String(bytes: accumulator, encoding: .utf8)
63+
}
64+
}
65+
}
66+
67+
#endif

0 commit comments

Comments
 (0)