Revision 73ea5effe5e8ad6dfaf4a3923830d89a35274663 authored by Kunal Dhariwal on 15 January 2019, 13:12:35 UTC, committed by Anton Kaliaev on 15 January 2019, 13:12:35 UTC
1 parent 4daca1a
Raw File
atomic_test.go
package benchmarks

import (
	"sync/atomic"
	"testing"
	"unsafe"
)

func BenchmarkAtomicUintPtr(b *testing.B) {
	b.StopTimer()
	pointers := make([]uintptr, 1000)
	b.Log(unsafe.Sizeof(pointers[0]))
	b.StartTimer()

	for j := 0; j < b.N; j++ {
		atomic.StoreUintptr(&pointers[j%1000], uintptr(j))
	}
}

func BenchmarkAtomicPointer(b *testing.B) {
	b.StopTimer()
	pointers := make([]unsafe.Pointer, 1000)
	b.Log(unsafe.Sizeof(pointers[0]))
	b.StartTimer()

	for j := 0; j < b.N; j++ {
		atomic.StorePointer(&pointers[j%1000], unsafe.Pointer(uintptr(j)))
	}
}
back to top