sequence

This article focuses on Gost’s CountWatch

CountWatch

gost/time/count.go

type CountWatch struct {
	start time.Time
}

func (w *CountWatch) Start() {
	var t time.Time
	if t.Equal(w.start) {
		w.start = time.Now()
	}
}

func (w *CountWatch) Reset() {
	w.start = time.Now()
}

func (w *CountWatch) Count() int64 {
	return time.Since(w.start).Nanoseconds()
}
Copy the code

CountWatch defines the start attribute, which provides the start, Reset, and Count methods. If Start is the initial value, set it to time.now. Reset Sets start to time.Now; Count Counts the number of nanoseconds between the current time and start

The instance

func countWatchDemo() {
	var cw gxtime.CountWatch
	cw.Start()
	//do something
	fmt.Println("cost:%d ns", cw.Count())
}
Copy the code

Start and count are used to obtain the interval. To continue using the interval, run Reset

summary

Gost’s CountWatch defines the start attribute, which provides the start, Reset, and Count methods. If Start is the initial value, set it to time.now. Reset Sets start to time.Now; Count Counts the number of nanoseconds between the current time and start.

doc

  • gost