teststring.go 761 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "strings"
  6. )
  7. func main() {
  8. sText := "aasdfasd:fasdf"
  9. st := time.Now().UnixNano()
  10. count :=0
  11. for i:=1 ; i<1000000 ; i++ {
  12. if idx := strings.IndexAny(sText, ":") ; idx != -1{
  13. count++
  14. }
  15. }
  16. ed := time.Now().UnixNano()
  17. fmt.Println("===>", count, ed-st)
  18. st = time.Now().UnixNano()
  19. count =0
  20. for i:=1 ; i<1000000 ; i++ {
  21. if idx := strings.Index(sText, ":") ; idx != -1{
  22. count++
  23. }
  24. }
  25. ed = time.Now().UnixNano()
  26. fmt.Println("===>", count, ed-st)
  27. st = time.Now().UnixNano()
  28. count =0
  29. for i:=1 ; i<1000000 ; i++ {
  30. if strings.Contains(sText, ":") {
  31. count++
  32. }
  33. }
  34. ed = time.Now().UnixNano()
  35. fmt.Println("===>", count, ed-st)
  36. }