Skip to content

Instantly share code, notes, and snippets.

@teivah
Last active May 26, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teivah/64d0f6735ed85a539fa8838c64a5e37d to your computer and use it in GitHub Desktop.
Save teivah/64d0f6735ed85a539fa8838c64a5e37d to your computer and use it in GitHub Desktop.
type SimpleStruct struct {
n int
}
func BenchmarkStructureFalseSharing(b *testing.B) {
structA := SimpleStruct{}
structB := SimpleStruct{}
wg := sync.WaitGroup{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg.Add(2)
go func() {
for j := 0; j < M; j++ {
structA.n += j
}
wg.Done()
}()
go func() {
for j := 0; j < M; j++ {
structB.n += j
}
wg.Done()
}()
wg.Wait()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment