profile_test.go 832 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package timeutil
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. )
  7. func TestProfileDataSeries_NilOrZero(t *testing.T) {
  8. pds1 := NewProfileDataSeries("test1", 0)
  9. fmt.Println(pds1.String())
  10. pds2 := NewProfileDataSeries("test2", 0)
  11. pds2.Start()
  12. fmt.Println(pds2.String())
  13. pds2.Stop()
  14. fmt.Println(pds2.String())
  15. }
  16. func TestProfileDataSeries_Series(t *testing.T) {
  17. pds := NewProfileDataSeries("test", 3)
  18. pds.Start()
  19. time.Sleep(10 * time.Millisecond)
  20. pds.Step("step1")
  21. time.Sleep(100 * time.Millisecond)
  22. pds.Step("step2")
  23. time.Sleep(5 * time.Millisecond)
  24. pds.Step("step3")
  25. time.Sleep(1 * time.Millisecond)
  26. pds.Stop()
  27. fmt.Println(len(pds.Series))
  28. for i, p := range pds.Series {
  29. if p == nil {
  30. fmt.Printf("%d nil\n", i)
  31. } else {
  32. fmt.Printf("%d %s %v\n", i, p.Name, p.Time)
  33. }
  34. }
  35. fmt.Println(pds.String())
  36. }