Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage data in blocks #6

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Manage data in blocks
outofforest committed Sep 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ef5efd508d7438a2f34aa4f0c309ffd2e0ee5e9b
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 {
@@ -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[:])
@@ -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
@@ -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[:])
@@ -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