Guest User

Untitled

a guest
Nov 18th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. let date_start = NSDate()
  2.  
  3. // Code to be executed
  4.  
  5. println("(-date_start.timeIntervalSinceNow)")
  6.  
  7. func testExample() {
  8.  
  9. self.measureBlock() {
  10. //do something you want to measure
  11. }
  12. }
  13.  
  14. func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
  15. let startTime = CFAbsoluteTimeGetCurrent()
  16. operation()
  17. let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
  18. println("Time elapsed for (title): (timeElapsed) s.")
  19. }
  20.  
  21. func timeElapsedInSecondsWhenRunningCode(operation: ()->()) -> Double {
  22. let startTime = CFAbsoluteTimeGetCurrent()
  23. operation()
  24. let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
  25. return Double(timeElapsed)
  26. }
  27.  
  28. printTimeElapsedWhenRunningCode(title:"map()") {
  29. let resultArray1 = randoms.map { pow(sin(CGFloat($0)), 10.0) }
  30. }
  31.  
  32. import Foundation
  33.  
  34. func measure(_ title: String, block: (() -> ()) -> ()) {
  35.  
  36. let startTime = CFAbsoluteTimeGetCurrent()
  37.  
  38. block {
  39. let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
  40. print("(title):: Time: (timeElapsed)")
  41. }
  42. }
  43.  
  44. measure("some title") { finish in
  45. myAsyncCall {
  46. finish()
  47. }
  48. // ...
  49. }
  50.  
  51. measure("some title") { finish in
  52. // code to benchmark
  53. finish()
  54. // ...
  55. }
Add Comment
Please, Sign In to add comment