Created
August 20, 2018 10:26
-
-
Save sayden/122eeaa5e82a4f7ee39cef273be18e99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
) | |
func Benchmark_Big(b *testing.B) { | |
b.Run("return by value", func(b *testing.B) { | |
var big bigStruct | |
for n := 0; n < b.N; n++ { | |
big = returnVal() | |
} | |
big.Var1[0] = 0 | |
}) | |
b.Run("return by named value", func(b *testing.B) { | |
var big bigStruct | |
for n := 0; n < b.N; n++ { | |
big = returnWithName() | |
} | |
big.Var1[0] = 0 | |
}) | |
b.Run("return named pointer", func(b *testing.B) { | |
var big *bigStruct | |
for n := 0; n < b.N; n++ { | |
big = returnNamedPointer() | |
} | |
big.Var1[0] = 0 | |
}) | |
b.Run("return pointer", func(b *testing.B) { | |
var big *bigStruct | |
for n := 0; n < b.N; n++ { | |
big = returnPointer() | |
} | |
big.Var1[0] = 0 | |
}) | |
} | |
func Benchmark_Small(b *testing.B) { | |
b.Run("return pointer", func(b *testing.B) { | |
var small *smallStruct | |
for n := 0; n < b.N; n++ { | |
small = returnPointerSmall() | |
} | |
small.ar[0] = 0 | |
}) | |
b.Run("return named pointer", func(b *testing.B) { | |
var small *smallStruct | |
for n := 0; n < b.N; n++ { | |
small = returnNamedPointerSmall() | |
} | |
small.ar[0] = 0 | |
}) | |
b.Run("return by value", func(b *testing.B) { | |
var small smallStruct | |
for n := 0; n < b.N; n++ { | |
small = returnValSmall() | |
} | |
small.ar[0] = 0 | |
}) | |
b.Run("return by named value", func(b *testing.B) { | |
var small smallStruct | |
for n := 0; n < b.N; n++ { | |
small = returnWithNameSmall() | |
} | |
small.ar[0] = 0 | |
}) | |
} | |
func Benchmark_Zendesk(b *testing.B) { | |
b.Run("return pointer", func(b *testing.B) { | |
var z *zendeskTicket | |
for n := 0; n < b.N; n++ { | |
z = returnPointerZendesk() | |
} | |
z.Status = "" | |
}) | |
b.Run("return by named pointer", func(b *testing.B) { | |
var z *zendeskTicket | |
for n := 0; n < b.N; n++ { | |
z = returnNamedPointerZendesk() | |
} | |
z.Status = "" | |
}) | |
b.Run("return by value", func(b *testing.B) { | |
var z zendeskTicket | |
for n := 0; n < b.N; n++ { | |
z = returnValZendesk() | |
} | |
z.Status = "" | |
}) | |
b.Run("return by named value", func(b *testing.B) { | |
var z zendeskTicket | |
for n := 0; n < b.N; n++ { | |
z = returnWithNameZendesk() | |
} | |
z.Status = "" | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment