Selaa lähdekoodia

Adds performance test for Data.checksum()

Valeriy Van 5 vuotta sitten
vanhempi
commit
b4a76b48a3
1 muutettua tiedostoa jossa 14 lisäystä ja 0 poistoa
  1. 14 0
      Tests/CryptoSwiftTests/DigestTests.swift

+ 14 - 0
Tests/CryptoSwiftTests/DigestTests.swift

@@ -220,6 +220,20 @@ final class DigestTests: XCTestCase {
     XCTAssert(data.checksum() == 0x96, "Invalid checksum")
   }
 
+  func testChecksumPerformance() {
+    let len = 1_000_000
+    let a = [UInt8](unsafeUninitializedCapacity: len) { buf, count in
+      for i in 0..<len {
+        buf[i] = UInt8.random(in: 0...UInt8.max)
+      }
+      count = len
+    }
+    let data: Data = Data(bytes: UnsafePointer<UInt8>(a), count: len)
+    self.measure {
+      _ = data.checksum()
+    }
+  }
+
   func testSHAPartialUpdates() {
     do {
       let testSize = 1024 * 1024 * 5