Guest User

Untitled

a guest
Jul 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package main_test
  2.  
  3. import (
  4. "testing"
  5. "fmt"
  6. )
  7.  
  8. func BenchmarkC1(b *testing.B) {
  9. a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
  10. for i := 0; i < b.N; i++ {
  11. a = copy1(a)
  12. }
  13. }
  14.  
  15. func BenchmarkC2(b *testing.B) {
  16. a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
  17. for i := 0; i < b.N; i++ {
  18. a = copy2(a)
  19. }
  20. }
  21.  
  22. func BenchmarkC3(b *testing.B) {
  23. a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
  24. for i := 0; i < b.N; i++ {
  25. a = copy3(a)
  26. }
  27. }
  28.  
  29. func BenchmarkC4(b *testing.B) {
  30. a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
  31. for i := 0; i < b.N; i++ {
  32. a = copy4(a)
  33. }
  34. }
  35.  
  36. func copy1(s string) string {
  37. return fmt.Sprintf("%s", s)
  38. }
  39.  
  40. func copy2(s string) string {
  41. return string([]byte(s))
  42. }
  43.  
  44. func copy3(a string) string {
  45. return (a + " ")[:len(a)]
  46. }
  47.  
  48. func copy4(a string) string {
  49. if len(a) == 0 {
  50. return ""
  51. }
  52. return a[0:1] + a[1:]
  53. }
Add Comment
Please, Sign In to add comment