time_test.go 683 B

123456789101112131415161718192021222324252627282930313233
  1. package util
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. )
  7. func TestSubTimeToSeconds(t *testing.T) {
  8. now := time.Now()
  9. time.Sleep(time.Microsecond * 100)
  10. t.Log(SubTimeToSeconds(now, time.Now()))
  11. }
  12. /**
  13. BenchmarkStringFmt-12 8401734 158 ns/op 48 B/op 3 allocs/op
  14. BenchmarkStringConn-12 69749120 19.0 ns/op 0 B/op 0 allocs/op
  15. */
  16. func BenchmarkStringFmt(b *testing.B) {
  17. str1 := "11111"
  18. str2 := "22222"
  19. for i := 0; i < b.N; i++ {
  20. fmt.Sprintf("%s%s", str1, str2)
  21. }
  22. }
  23. func BenchmarkStringConn(b *testing.B) {
  24. str1 := "11111"
  25. str2 := "22222"
  26. for i := 0; i < b.N; i++ {
  27. _ = str1 + str2
  28. }
  29. }