Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidleee/2c1e92aa4f0b35cca5a04a3e4399982f to your computer and use it in GitHub Desktop.

Select an option

Save davidleee/2c1e92aa4f0b35cca5a04a3e4399982f to your computer and use it in GitHub Desktop.

Revisions

  1. @DenTelezhkin DenTelezhkin revised this gist Mar 16, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions MeasureAppStartupTime.swift
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ func measureAppStartUpTime() -> Double {
    let start_time = kinfo.kp_proc.p_starttime
    var time : timeval = timeval(tv_sec: 0, tv_usec: 0)
    gettimeofday(&time, nil)
    let currentTimeMilliseconds = Double(time.tv_sec * 1000) + Double(time.tv_usec) / 1000.0
    let processTimeMilliseconds = Double(start_time.tv_sec * 1000) + Double(start_time.tv_usec) / 1000.0
    let currentTimeMilliseconds = Double(Int64(time.tv_sec) * 1000) + Double(time.tv_usec) / 1000.0
    let processTimeMilliseconds = Double(Int64(start_time.tv_sec) * 1000) + Double(start_time.tv_usec) / 1000.0
    return (currentTimeMilliseconds - processTimeMilliseconds) / 1000.0
    }
  2. @DenTelezhkin DenTelezhkin revised this gist Jan 18, 2018. No changes.
  3. @DenTelezhkin DenTelezhkin created this gist Jan 18, 2018.
    13 changes: 13 additions & 0 deletions MeasureAppStartupTime.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // Returns number of seconds passed between time when process was created and function was called
    func measureAppStartUpTime() -> Double {
    var kinfo = kinfo_proc()
    var size = MemoryLayout<kinfo_proc>.stride
    var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
    sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)
    let start_time = kinfo.kp_proc.p_starttime
    var time : timeval = timeval(tv_sec: 0, tv_usec: 0)
    gettimeofday(&time, nil)
    let currentTimeMilliseconds = Double(time.tv_sec * 1000) + Double(time.tv_usec) / 1000.0
    let processTimeMilliseconds = Double(start_time.tv_sec * 1000) + Double(start_time.tv_usec) / 1000.0
    return (currentTimeMilliseconds - processTimeMilliseconds) / 1000.0
    }