Created
November 12, 2016 19:11
-
-
Save divan/c3500bfbe0801b4dd10b8d596837cde7 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 funcptr | |
import "testing" | |
type LargeStruct struct { | |
f1, f2, f3, f4, f5, f6, f7, f8, f9, f10 uint64 | |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 uint64 | |
b1, b2, b3, b4, b5, b6, b7, b8, b9, b10 uint64 | |
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 uint64 | |
d1, d2, d3, d4, d5, d6, d7, d8, d9, d10 uint64 | |
e1, e2, e3, e4, e5, e6, e7, e8, e9, e10 uint64 | |
j1, j2, j3, j4, j5, j6, j7, j8, j9, j10 uint64 | |
k1, k2, k3, k4, k5, k6, k7, k8, k9, k10 uint64 | |
l1, l2, l3, l4, l5, l6, l7, l8, l9, l10 uint64 | |
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 uint64 | |
} | |
func Foo(arr [2e6]int64) int { return len(arr) } | |
func FooPtr(arr *[2e6]int64) int { return len(arr) } | |
func FooArray(s LargeStruct) int { return int(s.f1 + s.f2) } | |
func FooArrayPtr(s *LargeStruct) int { return int(s.f1 + s.f2) } | |
func BenchmarkFooArray(b *testing.B) { | |
a := [2e6]int64{} | |
for i := 0; i < b.N; i++ { | |
Foo(a) | |
} | |
} | |
func BenchmarkFooArrayPtr(b *testing.B) { | |
a := [2e6]int64{} | |
for i := 0; i < b.N; i++ { | |
FooPtr(&a) | |
} | |
} | |
func BenchmarkFoo(b *testing.B) { | |
a := LargeStruct{} | |
for i := 0; i < b.N; i++ { | |
FooArray(a) | |
} | |
} | |
func BenchmarkFooPtr(b *testing.B) { | |
a := LargeStruct{} | |
for i := 0; i < b.N; i++ { | |
FooArrayPtr(&a) | |
} | |
} |
Author
divan
commented
Nov 12, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment