Skip to content

Commit

Permalink
Manage data in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Sep 11, 2024
1 parent 209cf76 commit ef5efd5
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 124 deletions.
35 changes: 16 additions & 19 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package quantum

import (
"crypto/rand"
"math/rand"
"testing"
)

// go test -benchtime=100x -bench=BenchmarkQuantum -run=^$ -cpuprofile profile.out
// go test -benchtime=10x -bench=BenchmarkQuantum -run=^$ -cpuprofile profile.out
// go tool pprof -http="localhost:8000" pprofbin ./profile.out

type key struct {
Expand All @@ -18,9 +18,9 @@ func BenchmarkMaps(b *testing.B) {
b.ResetTimer()

db := map[key]int{}
keys := make([]key, 0, 10_000)
keys := make([]key, 0, 1000_000)

for i := range 10_000 {
for i := range cap(keys) {
var k key
_, _ = rand.Read(k.store[:])
_, _ = rand.Read(k.key[:])
Expand All @@ -34,13 +34,13 @@ func BenchmarkMaps(b *testing.B) {

for range b.N {
b.StartTimer()
for i := range 1000 {
for j := i * 10; j < i*10+10; j++ {
k := keys[j]
for range 1000 {
for range 30 {
k := keys[rand.Intn(len(keys))]
v2 := snapshot2[k]
v1 := snapshot1[k]
v := db[k]
snapshot2[k] = v + v1 + v2 + j
snapshot2[k] = v + v1 + v2
}
for k, v := range snapshot2 {
snapshot1[k] = v
Expand All @@ -60,9 +60,9 @@ func BenchmarkQuantum(b *testing.B) {
b.ResetTimer()

db := New[key, int]()
keys := make([]key, 0, 10_000)
keys := make([]key, 0, 1000_000)

for i := range 10_000 {
for i := range cap(keys) {
var k key
_, _ = rand.Read(k.store[:])
_, _ = rand.Read(k.key[:])
Expand All @@ -73,17 +73,14 @@ func BenchmarkQuantum(b *testing.B) {

for range b.N {
b.StartTimer()
snapshot1 := db.Next()
for i := range 1000 {
snapshot2 := snapshot1.Next()
for j := i * 10; j < i*10+10; j++ {
k := keys[j]
v, _ := snapshot2.Get(k)
snapshot2.Set(k, v+j)
for range 1000 {
db = db.Next()
for range 30 {
k := keys[rand.Intn(len(keys))]
v, _ := db.Get(k)
db.Set(k, v)
}
snapshot1 = snapshot2
}
db = snapshot1
b.StopTimer()
}
}
Loading

0 comments on commit ef5efd5

Please sign in to comment.