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 private func currentTimeIntervalSinceReferenceTime
XCTestMain.swift:39 var duration: TimeIntervalXCTimeUtilities.swift:23 private 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
XCTimeUtilities.swift:34 let start = currentTimeIntervalSinceReferenceTime()XCTimeUtilities.swift:36 let end = currentTimeIntervalSinceReferenceTime()(@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:35 let overallDuration = measureTimeExecutingBlock {XCTestCase.swift:53 let duration = measureTimeExecutingBlock {XCTestMain.swift:53 let overallDuration = measureTimeExecutingBlock {(timeInterval: TimeInterval) -> String { 0043 return String(round(timeInterval * 1000.0) / 1000.0) 0044 } 0045
XCTestCase.swift:76 XCTPrint("Test Case '\(method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")XCTestCase.swift:91 XCTPrint("Executed \(tests.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(unexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) (\(printableStringForTimeInterval(overallDuration))) seconds")XCTestCase.swift:91 XCTPrint("Executed \(tests.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(unexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) (\(printableStringForTimeInterval(overallDuration))) seconds")XCTestMain.swift:70 XCTPrint("Total executed \(XCTAllRuns.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(totalUnexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) (\(printableStringForTimeInterval(overallDuration))) seconds")XCTestMain.swift:70 XCTPrint("Total executed \(XCTAllRuns.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(totalUnexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) (\(printableStringForTimeInterval(overallDuration))) seconds")