Skip to content

Instantly share code, notes, and snippets.

@prashantv
Created September 2, 2016 04:04
Show Gist options
  • Save prashantv/3376439d053fa2d3ec6d687b174ebdf4 to your computer and use it in GitHub Desktop.
Save prashantv/3376439d053fa2d3ec6d687b174ebdf4 to your computer and use it in GitHub Desktop.
package main
import (
"sync/atomic"
"testing"
)
func BenchmarkAtomicSerial(b *testing.B) {
var n int64
for i := 0; i < b.N; i++ {
atomic.AddInt64(&n, 1)
}
}
func BenchmarkAtomicConcurrent(b *testing.B) {
var n int64
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
atomic.AddInt64(&n, 1)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment