-
Notifications
You must be signed in to change notification settings - Fork 3
/
NBKFlexibleWidth+Text.swift
110 lines (87 loc) · 3.75 KB
/
NBKFlexibleWidth+Text.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//=----------------------------------------------------------------------------=
// This source file is part of the Numberick open source project.
//
// Copyright (c) 2023 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
#if !DEBUG
import NBKCoreKit
import NBKFlexibleWidthKit
import XCTest
private typealias X = [UInt]
private typealias X64 = [UInt64]
private typealias X32 = [UInt32]
//*============================================================================*
// MARK: * NBK x Flexible Width x Text x UIntXL
//*============================================================================*
final class NBKFlexibleWidthBenchmarksOnTextAsUIntXL: XCTestCase {
typealias T = UIntXL
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
static let decoded = NBK.blackHoleIdentity(T(encoded, radix: 16)!)
static let encoded = NBK.blackHoleIdentity(String(repeating: "1", count: 64))
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=
func testDecodingRadix10() {
var radix = NBK.blackHoleIdentity(10)
var encoded = NBK.blackHoleIdentity(Self.encoded)
for _ in 0 ..< 250_000 {
NBK.blackHole(T(encoded, radix: radix)!)
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&encoded)
}
}
func testDecodingRadix16() {
var radix = NBK.blackHoleIdentity(16)
var encoded = NBK.blackHoleIdentity(Self.encoded)
for _ in 0 ..< 250_000 {
NBK.blackHole(T(encoded, radix: radix)!)
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&encoded)
}
}
func testEncodingRadix10() {
var radix = NBK.blackHoleIdentity(10)
var decoded = NBK.blackHoleIdentity(Self.decoded)
for _ in 0 ..< 250_000 {
NBK.blackHole(String(decoded, radix: radix))
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&decoded)
}
}
func testEncodingRadix16() {
var radix = NBK.blackHoleIdentity(16)
var decoded = NBK.blackHoleIdentity(Self.decoded)
for _ in 0 ..< 250_000 {
NBK.blackHole(String(decoded, radix: radix))
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&decoded)
}
}
//=------------------------------------------------------------------------=
// MARK: Tests x Swift Standard Library Methods
//=------------------------------------------------------------------------=
func testEncodingUsingSwiftStdlibRadix10() {
var radix = NBK.blackHoleIdentity(10)
var decoded = NBK.blackHoleIdentity(Self.decoded)
for _ in 0 ..< 1_000 {
NBK.blackHole(String(NBK.someSwiftBinaryInteger(decoded), radix: radix))
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&decoded)
}
}
func testEncodingUsingSwiftStdlibRadix16() {
var radix = NBK.blackHoleIdentity(16)
var decoded = NBK.blackHoleIdentity(Self.decoded)
for _ in 0 ..< 1_000 {
NBK.blackHole(String(NBK.someSwiftBinaryInteger(decoded), radix: radix))
NBK.blackHoleInoutIdentity(&radix)
NBK.blackHoleInoutIdentity(&decoded)
}
}
}
#endif