diff --git a/misc/timer/timer.go b/misc/timer/timer.go new file mode 100644 index 0000000..66db4eb --- /dev/null +++ b/misc/timer/timer.go @@ -0,0 +1,10 @@ +package timer + +import "time" + +func Span() func() time.Duration { + t := time.Now() + return func() time.Duration { + return time.Since(t) + } +} diff --git a/misc/timer/timer_test.go b/misc/timer/timer_test.go new file mode 100644 index 0000000..9031bdd --- /dev/null +++ b/misc/timer/timer_test.go @@ -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()) +}