@@ -19,6 +19,32 @@ import Basic
19
19
#if false
20
20
21
21
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
+
22
48
func test1MBOf16ByteArrays_X100( ) {
23
49
// Test writing 1MB worth of 16 byte strings.
24
50
let bytes16 = [ UInt8] ( repeating: 0 , count: 1 << 4 )
@@ -34,6 +60,23 @@ class OutputByteStreamPerfTests: XCTestCase {
34
60
}
35
61
}
36
62
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
+
37
80
func test1MBOf1KByteArrays_X1000( ) {
38
81
// Test writing 1MB worth of 1K byte strings.
39
82
let bytes1k = [ UInt8] ( repeating: 0 , count: 1 << 10 )
0 commit comments