Created
          September 17, 2018 06:40 
        
      - 
      
 - 
        
Save Alexander-Ignition/2f9b1620367dd9b399e36be56792becb to your computer and use it in GitHub Desktop.  
    Measure on Darwin Match
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func measure(_ name: String, _ block: () -> Void) { | |
| let machToSeconds: Double = { | |
| var timebase: mach_timebase_info_data_t = mach_timebase_info_data_t() | |
| mach_timebase_info(&timebase) | |
| return Double(timebase.numer) / Double(timebase.denom) * 1e-9 | |
| }() | |
| let startTime = mach_absolute_time() | |
| block() | |
| let endTime = mach_absolute_time() | |
| print(name, (machToSeconds * Double(endTime - startTime))) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment