/*
Stops this timer, returning back a map of names to durations.
*/
Stops this timer, returning back a map of names to durations.
/ * Stops this timer returning back a map of names to durations . * /
func (t *Timer) StopTimer() map[string]time.Duration {
	t.AddMark(TimerMarkEnd)
	times := make(map[string]time.Duration, len(t.Marks))
	totalDuration := t.Marks[len(t.Marks)-1].mark.Sub(t.Marks[0].mark)
	times[TimerMarkTotal] = totalDuration
	t.Marks = append(t.Marks, TimerMark{
		mark:     time.Now(),
		Duration: totalDuration,
		Name:     TimerMarkTotal,
	})
	for i := 1; i < len(t.Marks); i++ {
		currentDuration := t.Marks[i].mark.Sub(t.Marks[i-1].mark)
		times[t.Marks[i-1].Name] = currentDuration
		t.Marks[i-1].Duration = currentDuration
	}
	t.Marks = t.Marks[:len(t.Marks)-1]
	return times
}
func ( t * Timer ) StopTimer ( ) map [ string ] time . Duration { t . AddMark ( TimerMarkEnd ) times := make ( map [ string ] time . Duration , len ( t . Marks ) ) totalDuration := t . Marks [ len ( t . Marks ) - 1 ] . mark . Sub ( t . Marks [ 0 ] . mark ) times [ TimerMarkTotal ] = totalDuration t . Marks = append ( t . Marks , TimerMark { mark : time . Now ( ) , Duration : totalDuration , Name : TimerMarkTotal , } ) for i := 1 ; i < len ( t . Marks ) ; i ++ { currentDuration := t . Marks [ i ] . mark . Sub ( t . Marks [ i - 1 ] . mark ) times [ t . Marks [ i - 1 ] . Name ] = currentDuration t . Marks [ i - 1 ] . Duration = currentDuration } t . Marks = t . Marks [ : len ( t . Marks ) - 1 ] return times }
Stops this timer, returning back a map of names to durations.
Stops this timer returning back a map of names to durations .
// ALWAYS stop the timer first before doing anything else // add a special extra mark for total // Then go over each mark and figure out the difference between the current one and the previous // Remove the last mark since it's no longer needed // Don't add an extra duration for the stop event