Skip to content

Commit

Permalink
feat(misc/timer): time cost func
Browse files Browse the repository at this point in the history
  • Loading branch information
saitofun committed Jul 22, 2024
1 parent aa4898a commit 1018644
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions misc/timer/timer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package timer

import "time"

func Span() func() time.Duration {
t := time.Now()
return func() time.Duration {
return time.Since(t)
}
}
14 changes: 14 additions & 0 deletions misc/timer/timer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package timer_test

import (
"testing"
"time"

"github.com/xoctopus/x/misc/timer"
)

func TestSpan(t *testing.T) {
cost := timer.Span()
time.Sleep(time.Second)
t.Log(cost())
}

0 comments on commit 1018644

Please sign in to comment.