Exemple #1
0
func TestTimer(t *testing.T) {

	timer.Start("is here")
	err := timer.Stop("not here")

	if err == nil {
		t.Fatalf("job: 'not here' is here\n")
	}

	err = timer.Stop("is here")

	if err != nil {
		t.Fatalf("job: 'is here' is not here\n")
	}

	delta, err := timer.Delta("is here")

	if err != nil {
		t.Fatalf("job: 'is here' still not here..\n")
	}

	if delta < 0 {
		t.Fatalf("delta = %d < 0 ns\n", delta)
	}

	delta = timer.Hour*4 + timer.Minute*7 + timer.Second*3 + timer.Millisecond*9

	tid := timer.Nano2Time(delta)

	if tid.Hours != 4 {
		t.Fatalf("timer.Nano2Time() 4 != %d\n", tid.Hours)
	}

	if tid.Minutes != 7 {
		t.Fatalf("timer.Nano2Time() 7 != %d\n", tid.Minutes)
	}

	if tid.Seconds != 3 {
		t.Fatalf("timer.Nano2Time() 3 != %d\n", tid.Seconds)
	}

	if tid.Milliseconds != 9 {
		t.Fatalf("timer.Nano2Time() 9 != %d\n", tid.Milliseconds)
	}

}
Exemple #2
0
Fichier : main.go Projet : ssrl/mgd
func reportTime() {
	timer.Stop("everything")
	delta, _ := timer.Delta("everything")
	say.Printf("time used: %s\n", timer.Nano2Time(delta))
}