|
| 1 | +// Copyright (c) 2018 Timofey Solomko |
| 2 | +// Licensed under MIT License |
| 3 | +// |
| 4 | +// See LICENSE for license information |
| 5 | + |
| 6 | +import XCTest |
| 7 | +import BitByteData |
| 8 | + |
| 9 | +class ByteReaderBenchmarks: XCTestCase { |
| 10 | + |
| 11 | + func testByte() { |
| 12 | + self.measure { |
| 13 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 14 | + |
| 15 | + for _ in 0..<5_000_000 { |
| 16 | + _ = byteReader.byte() |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + func testBytes() { |
| 22 | + self.measure { |
| 23 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 24 | + |
| 25 | + for _ in 0..<500_000 { |
| 26 | + _ = byteReader.bytes(count: 20) |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + func testIntFromBytes() { |
| 32 | + self.measure { |
| 33 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 34 | + |
| 35 | + for _ in 0..<1_000_000 { |
| 36 | + _ = byteReader.int(fromBytes: 7) |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + func testUint16() { |
| 42 | + self.measure { |
| 43 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 44 | + |
| 45 | + for _ in 0..<1_000_000 { |
| 46 | + _ = byteReader.uint16() |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + func testUint16FromBytes() { |
| 52 | + self.measure { |
| 53 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 54 | + |
| 55 | + for _ in 0..<2_000_000 { |
| 56 | + _ = byteReader.uint16(fromBytes: 1) |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + func testUint32() { |
| 62 | + self.measure { |
| 63 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 64 | + |
| 65 | + for _ in 0..<500_000 { |
| 66 | + _ = byteReader.uint32() |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + func testUint32FromBytes() { |
| 72 | + self.measure { |
| 73 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 74 | + |
| 75 | + for _ in 0..<500_000 { |
| 76 | + _ = byteReader.uint32(fromBytes: 3) |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + func testUint64() { |
| 82 | + self.measure { |
| 83 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 84 | + |
| 85 | + for _ in 0..<1_00_000 { |
| 86 | + _ = byteReader.uint64() |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + func testUint64FromBytes() { |
| 92 | + self.measure { |
| 93 | + let byteReader = ByteReader(data: Data(count: 10_485_760)) // 10 MB |
| 94 | + |
| 95 | + for _ in 0..<1_000_000 { |
| 96 | + _ = byteReader.uint64(fromBytes: 7) |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | +} |
0 commit comments