Skip to content

Commit

Permalink
time: init measure func time
Browse files Browse the repository at this point in the history
  • Loading branch information
5aaee9 committed Aug 1, 2023
1 parent ef08fd0 commit c6ea021
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkgs/time/func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package time

import "time"

func MeasureFuncTime(target func()) time.Duration {
t := time.Now()
target()

return time.Since(t)
}

16 changes: 16 additions & 0 deletions pkgs/time/func_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package time

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestMeasureFuncTime(t *testing.T) {
ret := MeasureFuncTime(func() {
time.Sleep(time.Second * 2)
})

assert.Equal(t, 2000, int(ret/time.Millisecond))
}

0 comments on commit c6ea021

Please sign in to comment.