Skip to content

Commit d86095a

Browse files
Added some additional benchmarks.
1 parent b5a7d9d commit d86095a

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

btree/palm/tree_test.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func BenchmarkReadAndWrites(b *testing.B) {
437437
keys = append(keys, generateRandomKeys(numItems))
438438
}
439439

440-
tree := newTree(16, 8)
440+
tree := newTree(8, 8)
441441
b.ResetTimer()
442442

443443
for i := 0; i < b.N; i++ {
@@ -447,25 +447,27 @@ func BenchmarkReadAndWrites(b *testing.B) {
447447
}
448448

449449
func BenchmarkSimultaneousReadsAndWrites(b *testing.B) {
450-
numItems := 1000
450+
numItems := 10000
451451
numRoutines := 8
452-
keys := make([]common.Comparators, 0, numRoutines)
453-
for i := 0; i < numRoutines; i++ {
454-
keys = append(keys, generateRandomKeys(numItems))
452+
keys := generateRandomKeys(numItems)
453+
chunks := chunkKeys(keys, int64(numRoutines))
454+
455+
trees := make([]*ptree, 0, numItems)
456+
for i := 0; i < b.N; i++ {
457+
trees = append(trees, newTree(8, 8))
455458
}
456459

457-
tree := newTree(16, 8)
458460
var wg sync.WaitGroup
459461
b.ResetTimer()
460462

461463
for i := 0; i < b.N; i++ {
462464
wg.Add(numRoutines)
463465
for j := 0; j < numRoutines; j++ {
464-
go func(j int) {
465-
tree.Insert(keys[j]...)
466-
tree.Get(keys[j]...)
466+
go func(i, j int) {
467+
trees[i].Insert(chunks[j]...)
468+
trees[i].Get(chunks[j]...)
467469
wg.Done()
468-
}(j)
470+
}(i, j)
469471
}
470472

471473
wg.Wait()
@@ -475,12 +477,15 @@ func BenchmarkSimultaneousReadsAndWrites(b *testing.B) {
475477
func BenchmarkBulkAdd(b *testing.B) {
476478
numItems := 10000
477479
keys := generateRandomKeys(numItems)
480+
trees := make([]*ptree, 0, b.N)
481+
for i := 0; i < b.N; i++ {
482+
trees = append(trees, newTree(8, 8))
483+
}
478484

479485
b.ResetTimer()
480486

481487
for i := 0; i < b.N; i++ {
482-
tree := newTree(8, 8)
483-
tree.Insert(keys...)
488+
trees[i].Insert(keys...)
484489
}
485490
}
486491

@@ -515,7 +520,7 @@ func BenchmarkBulkAddToExisting(b *testing.B) {
515520
func BenchmarkGet(b *testing.B) {
516521
numItems := 10000
517522
keys := generateRandomKeys(numItems)
518-
tree := newTree(32, 8)
523+
tree := newTree(8, 8)
519524
tree.Insert(keys...)
520525

521526
b.ResetTimer()

btree/plus/btree_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package plus
1818

1919
import (
20+
"sync"
2021
"testing"
2122

2223
"github.com/stretchr/testify/assert"
@@ -394,3 +395,34 @@ func BenchmarkReadAndWrites(b *testing.B) {
394395
tree.Get(ks[i]...)
395396
}
396397
}
398+
399+
func BenchmarkSimultaneousReadsAndWrites(b *testing.B) {
400+
numItems := 10000
401+
numRoutines := 8
402+
keys := constructRandomMockKeys(numItems)
403+
chunks := chunkKeys(keys, int64(numRoutines))
404+
405+
trees := make([]*btree, 0, numItems)
406+
for i := 0; i < b.N; i++ {
407+
trees = append(trees, newBTree(8))
408+
}
409+
410+
var wg sync.WaitGroup
411+
var lock sync.Mutex
412+
b.ResetTimer()
413+
414+
for i := 0; i < b.N; i++ {
415+
wg.Add(numRoutines)
416+
for j := 0; j < numRoutines; j++ {
417+
go func(i, j int) {
418+
lock.Lock()
419+
trees[i].Insert(chunks[j]...)
420+
trees[i].Get(chunks[j]...)
421+
lock.Unlock()
422+
wg.Done()
423+
}(i, j)
424+
}
425+
426+
wg.Wait()
427+
}
428+
}

btree/plus/mock_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ limitations under the License.
1616

1717
package plus
1818

19+
func chunkKeys(ks keys, numParts int64) []keys {
20+
parts := make([]keys, numParts)
21+
for i := int64(0); i < numParts; i++ {
22+
parts[i] = ks[i*int64(len(ks))/numParts : (i+1)*int64(len(ks))/numParts]
23+
}
24+
return parts
25+
}
26+
1927
type mockKey struct {
2028
value int
2129
}

0 commit comments

Comments
 (0)