cost.go 604 Bytes
Newer Older
“李磊”'s avatar
“李磊” committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package common

import (
	"fmt"
	"time"

	"linkfog.com/public/lib/l"
)

func TimeCost(describe string) func() {
	start := time.Now()
	return func() {
		tc := time.Since(start)
		l.Infof(describe+" cost %v", tc)
	}
}

// Deprecated invalid usage
func TimeCostString(describe string) func() string {
	start := time.Now()
	return func() string {
		tc := time.Since(start)
		return fmt.Sprintf(describe+" cost %v", tc)
	}
}

func TimeCostDebug(describe string) func() {
	start := time.Now()
	return func() {
		tc := time.Since(start)
		l.Debugf(describe+" cost %v", tc)
	}
}