-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dev
committed
Feb 18, 2024
1 parent
d481450
commit baf2fe2
Showing
12 changed files
with
439 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,5 @@ node_modules/ | |
|
||
# build directory | ||
/dist/ | ||
|
||
*.db* |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package swap | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"unsafe" | ||
) | ||
|
||
func BenchmarkParallelAtomicPointerRead(b *testing.B) { | ||
var ptr unsafe.Pointer | ||
data := make(map[int]int) | ||
data[1] = 1 | ||
atomic.StorePointer(&ptr, unsafe.Pointer(&data)) | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
localData := (*map[int]int)(atomic.LoadPointer(&ptr)) | ||
_ = (*localData)[1] | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkParallelAtomicValueRead(b *testing.B) { | ||
var ptr atomic.Value | ||
data := make(map[int]int) | ||
data[1] = 1 | ||
ptr.Store(data) | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
localData := ptr.Load().(map[int]int) | ||
_ = localData[1] | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkParallelRWMutexRead(b *testing.B) { | ||
var mutex sync.RWMutex | ||
data := make(map[int]int) | ||
data[1] = 1 | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
mutex.RLock() | ||
_ = data[1] | ||
mutex.RUnlock() | ||
} | ||
}) | ||
} |
Oops, something went wrong.