You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
556 B

  1. package benchmarks
  2. import (
  3. "sync/atomic"
  4. "testing"
  5. "unsafe"
  6. )
  7. func BenchmarkAtomicUintPtr(b *testing.B) {
  8. b.StopTimer()
  9. pointers := make([]uintptr, 1000)
  10. b.Log(unsafe.Sizeof(pointers[0]))
  11. b.StartTimer()
  12. for j := 0; j < b.N; j++ {
  13. atomic.StoreUintptr(&pointers[j%1000], uintptr(j))
  14. }
  15. }
  16. func BenchmarkAtomicPointer(b *testing.B) {
  17. b.StopTimer()
  18. pointers := make([]unsafe.Pointer, 1000)
  19. b.Log(unsafe.Sizeof(pointers[0]))
  20. b.StartTimer()
  21. for j := 0; j < b.N; j++ {
  22. atomic.StorePointer(&pointers[j%1000], unsafe.Pointer(uintptr(j)))
  23. }
  24. }