-
Notifications
You must be signed in to change notification settings - Fork 3
/
NBKFlexibleWidth+Addition.swift
81 lines (64 loc) · 2.62 KB
/
NBKFlexibleWidth+Addition.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
//=----------------------------------------------------------------------------=
// 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 Addition x UIntXL
//*============================================================================*
final class NBKFlexibleWidthBenchmarksOnAdditionAsUIntXL: XCTestCase {
typealias T = UIntXL
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=
func testAdd() {
var lhs = NBK.blackHoleIdentity(T(x64:[~0, ~1, ~2, ~3] as X64))
var rhs = NBK.blackHoleIdentity(T(x64:[ 0, 1, 2, 3] as X64))
for _ in 0 ..< 5_000_000 {
NBK.blackHole(lhs += rhs)
NBK.blackHoleInoutIdentity(&lhs)
NBK.blackHoleInoutIdentity(&rhs)
}
}
func testAdding() {
var lhs = NBK.blackHoleIdentity(T(x64:[~0, ~1, ~2, ~3] as X64))
var rhs = NBK.blackHoleIdentity(T(x64:[ 0, 1, 2, 3] as X64))
for _ in 0 ..< 1_000_000 {
NBK.blackHole(lhs + rhs)
NBK.blackHoleInoutIdentity(&lhs)
NBK.blackHoleInoutIdentity(&rhs)
}
}
//=------------------------------------------------------------------------=
// MARK: Tests x Digit
//=------------------------------------------------------------------------=
func testAddDigit() {
var lhs = NBK.blackHoleIdentity(T(x64:[~0, ~1, ~2, ~3] as X64))
var rhs = NBK.blackHoleIdentity(UInt.max)
for _ in 0 ..< 5_000_000 {
NBK.blackHole(lhs += rhs)
NBK.blackHoleInoutIdentity(&lhs)
NBK.blackHoleInoutIdentity(&rhs)
}
}
func testAddingDigit() {
var lhs = NBK.blackHoleIdentity(T(x64:[~0, ~1, ~2, ~3] as X64))
var rhs = NBK.blackHoleIdentity(UInt.max)
for _ in 0 ..< 1_000_000 {
NBK.blackHole(lhs + rhs)
NBK.blackHoleInoutIdentity(&lhs)
NBK.blackHoleInoutIdentity(&rhs)
}
}
}
#endif