CommonCryptoTests.swift 990 B

1234567891011121314151617181920212223242526
  1. //
  2. // CommonCryptoTests.swift
  3. // CryptoSwift
  4. //
  5. // Created by Michael Ledin on 22.08.16.
  6. // Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. import XCTest
  9. @testable import CryptoSwift
  10. final class CryptoSwiftTests: XCTestCase {
  11. func testMD5PerformanceCommonCrypto() {
  12. self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
  13. let buf: UnsafeMutableRawPointer = calloc(1024 * 1024, MemoryLayout<UInt8>.size)
  14. let data = NSData(bytes: buf, length: 1024 * 1024)
  15. let md = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
  16. self.startMeasuring()
  17. CC_MD5(data.bytes, CC_LONG(data.length), md)
  18. self.stopMeasuring()
  19. md.deallocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
  20. md.deinitialize()
  21. buf.deallocate(bytes: 1024 * 1024, alignedTo: MemoryLayout<UInt8>.alignment)
  22. })
  23. }
  24. }