Skip to content

Commit

Permalink
util: add TimeProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 16, 2021
1 parent cce9e77 commit 2d520df
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/util/profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package util

import "time"

type TimeProfile struct {
StartTime, EndTime time.Time
Duration time.Duration
}

func StartTimeProfile() TimeProfile {
return TimeProfile{StartTime: time.Now()}
}

func (p *TimeProfile) TilNow() time.Duration {
return time.Now().Sub(p.StartTime)
}

func (p *TimeProfile) Stop() time.Duration {
p.EndTime = time.Now()
p.Duration = p.EndTime.Sub(p.StartTime)
return p.Duration
}

0 comments on commit 2d520df

Please sign in to comment.