github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/x/misc/timer/timer.go (about)

     1  package timer
     2  
     3  import "time"
     4  
     5  func Start() func() time.Duration {
     6  	t := time.Now()
     7  	return func() time.Duration { return time.Since(t) }
     8  }
     9  
    10  type Span struct {
    11  	t    time.Time
    12  	cost func() time.Duration
    13  }
    14  
    15  func StartSpan() *Span { return &Span{t: time.Now()} }
    16  
    17  func (s *Span) Cost() time.Duration  { return time.Since(s.t) }
    18  func (s *Span) StartedAt() time.Time { return s.t }