0001 // This source file is part of the Swift.org open source project 0002 // 0003 // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors 0004 // Licensed under Apache License v2.0 with Runtime Library Exception 0005 // 0006 // See http://swift.org/LICENSE.txt for license information 0007 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 0008 // 0009 // 0010 // XCTimeUtilities.swift 0011 // Some simple functions for working with "time intervals". 0012 // 0013 0014 #if os(Linux) || os(FreeBSD) 0015 import Glibc 0016 #else 0017 import Darwin 0018 #endif 0019 0020 internal typealias TimeInterval= Double 0021 0022 /// Returns the number of seconds since the reference time as a Double. 0023 internal func currentTimeIntervalSinceReferenceTime
XCTestCase.swift:109 private func postTestInvocation(end: TimeInterval, state: XCTestCaseState) {XCTestCase.swift:154 var start: TimeInterval = 0.0XCTestCase.swift:155 var totalDuration: TimeInterval = 0.0XCTestMain.swift:34 var duration: TimeIntervalXCTimeUtilities.swift:23 internal func currentTimeIntervalSinceReferenceTime() -> TimeInterval {XCTimeUtilities.swift:25 let currentTime = withUnsafeMutablePointer(&tv, { (t: UnsafeMutablePointer<timeval>) -> TimeInterval inXCTimeUtilities.swift:27 return TimeInterval(t.memory.tv_sec) + TimeInterval(t.memory.tv_usec) / 1000000.0XCTimeUtilities.swift:27 return TimeInterval(t.memory.tv_sec) + TimeInterval(t.memory.tv_usec) / 1000000.0XCTimeUtilities.swift:33 internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> TimeInterval {XCTimeUtilities.swift:42 internal func printableStringForTimeInterval(timeInterval: TimeInterval) -> String {() -> TimeInterval { 0024 var tv = timeval() 0025 let currentTime = withUnsafeMutablePointer(&tv, { (t: UnsafeMutablePointer<timeval>) -> TimeInterval in 0026 gettimeofday(t, nil) 0027 return TimeInterval(t.memory.tv_sec) + TimeInterval(t.memory.tv_usec) / 1000000.0 0028 }) 0029 return currentTime 0030 } 0031 0032 /// Execute the given block and return the time spent during execution 0033 internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> TimeInterval { 0034 let start = currentTimeIntervalSinceReferenceTime() 0035 block() 0036 let end = currentTimeIntervalSinceReferenceTime() 0037 0038 return end - start 0039 } 0040 0041 /// Returns a string version of the given time interval rounded to no more than 3 decimal places. 0042 internal func printableStringForTimeInterval
XCTestCase.swift:70 self.postTestInvocation(currentTimeIntervalSinceReferenceTime(), state: state)XCTestCase.swift:88 state.start = currentTimeIntervalSinceReferenceTime()XCTestCase.swift:97 self.postTestInvocation(currentTimeIntervalSinceReferenceTime(), state: state)XCTimeUtilities.swift:34 let start = currentTimeIntervalSinceReferenceTime()XCTimeUtilities.swift:36 let end = currentTimeIntervalSinceReferenceTime()(timeInterval: TimeInterval) -> String { 0043 return String(round(timeInterval * 1000.0) / 1000.0) 0044 } 0045
XCTestCase.swift:125 print("Test Case '\(state.method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")XCTestCase.swift:140 print("Executed \(state.count) test\(testCountSuffix), with \(state.totalFailures) failure\(failureSuffix) (\(state.unexpectedFailures) unexpected) in \(printableStringForTimeInterval(state.totalDuration)) seconds")XCTestMain.swift:84 print("Total executed \(XCTAllRuns.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(totalUnexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) seconds")