// main.swift // SwiftList - By Michael G. Workman // // An Example Swift application that builds and outputs a list // // This application freely distributable under terms of MIT open source license import Foundation import CoreFoundation // class for timing the list creation and display class AlgorithmTimer { let startTime:CFAbsoluteTime var endTime:CFAbsoluteTime? init() { startTime = CFAbsoluteTimeGetCurrent() } func stop() -> CFAbsoluteTime { endTime = CFAbsoluteTimeGetCurrent() return duration! } var duration:CFAbsoluteTime? { if let endTime = endTime { return endTime - startTime } else { return nil } } } // set timer and start var timer = AlgorithmTimer() // create list array of integers var intList = Array() // populate list with 100 thousand consecutive integer numbers for i in 1...100000 { intList.append(i); } // output contents of list one element at a time for i in intList { print(i) } // get the amount of time it took to complete print("Swift time to build and display list: \(timer.stop()) seconds") print("Number elements: \(intList.endIndex)")