Skip to content

Commit ec649e5

Browse files
committed
[Tests] Add more perf tests for OutputByteStream
1 parent 767a222 commit ec649e5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Tests/Basic/OutputByteStreamPerfTests.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ import Basic
1919
#if false
2020

2121
class OutputByteStreamPerfTests: XCTestCase {
22+
23+
func test1MBOfByte_X10() {
24+
let byte = UInt8(0)
25+
measure {
26+
for _ in 0..<10 {
27+
let stream = OutputByteStream()
28+
for _ in 0..<(1 << 20) {
29+
stream <<< byte
30+
}
31+
XCTAssertEqual(stream.bytes.count, 1 << 20)
32+
}
33+
}
34+
}
35+
36+
func test1MBOfCharacters_X1() {
37+
measure {
38+
for _ in 0..<1 {
39+
let stream = OutputByteStream()
40+
for _ in 0..<(1 << 20) {
41+
stream <<< Character("X")
42+
}
43+
XCTAssertEqual(stream.bytes.count, 1 << 20)
44+
}
45+
}
46+
}
47+
2248
func test1MBOf16ByteArrays_X100() {
2349
// Test writing 1MB worth of 16 byte strings.
2450
let bytes16 = [UInt8](repeating: 0, count: 1 << 4)
@@ -34,6 +60,23 @@ class OutputByteStreamPerfTests: XCTestCase {
3460
}
3561
}
3662

63+
// This should give same performance as 16ByteArrays_X100.
64+
func test1MBOf16ByteArraySlice_X100() {
65+
let bytes32 = [UInt8](repeating: 0, count: 1 << 5)
66+
// Test writing 1MB worth of 16 byte strings.
67+
let bytes16 = bytes32.suffix(from: bytes32.count/2)
68+
69+
measure {
70+
for _ in 0..<100 {
71+
let stream = OutputByteStream()
72+
for _ in 0..<(1 << 16) {
73+
stream <<< bytes16
74+
}
75+
XCTAssertEqual(stream.bytes.count, 1 << 20)
76+
}
77+
}
78+
}
79+
3780
func test1MBOf1KByteArrays_X1000() {
3881
// Test writing 1MB worth of 1K byte strings.
3982
let bytes1k = [UInt8](repeating: 0, count: 1 << 10)

0 commit comments

Comments
 (0)