Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main_test
- import (
- "testing"
- "fmt"
- )
- func BenchmarkC1(b *testing.B) {
- a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
- for i := 0; i < b.N; i++ {
- a = copy1(a)
- }
- }
- func BenchmarkC2(b *testing.B) {
- a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
- for i := 0; i < b.N; i++ {
- a = copy2(a)
- }
- }
- func BenchmarkC3(b *testing.B) {
- a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
- for i := 0; i < b.N; i++ {
- a = copy3(a)
- }
- }
- func BenchmarkC4(b *testing.B) {
- a := "121212123123231231231231311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111123123"
- for i := 0; i < b.N; i++ {
- a = copy4(a)
- }
- }
- func copy1(s string) string {
- return fmt.Sprintf("%s", s)
- }
- func copy2(s string) string {
- return string([]byte(s))
- }
- func copy3(a string) string {
- return (a + " ")[:len(a)]
- }
- func copy4(a string) string {
- if len(a) == 0 {
- return ""
- }
- return a[0:1] + a[1:]
- }
Add Comment
Please, Sign In to add comment