github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/prolly/benchmark/benchmark_write_test.go (about) 1 // Copyright 2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package benchmark 16 17 import ( 18 "context" 19 "math/rand" 20 "testing" 21 ) 22 23 func BenchmarkMapUpdate(b *testing.B) { 24 b.Run("benchmark maps 10k", func(b *testing.B) { 25 benchmarkProllyMapUpdate(b, 10_000, 1) 26 benchmarkTypesMapUpdate(b, 10_000, 1) 27 }) 28 b.Run("benchmark maps 100k", func(b *testing.B) { 29 benchmarkProllyMapUpdate(b, 100_000, 1) 30 benchmarkTypesMapUpdate(b, 100_000, 1) 31 }) 32 b.Run("benchmark maps 1M", func(b *testing.B) { 33 benchmarkProllyMapUpdate(b, 1_000_000, 1) 34 benchmarkTypesMapUpdate(b, 1_000_000, 1) 35 }) 36 } 37 38 func BenchmarkProllySmallWrites(b *testing.B) { 39 benchmarkProllyMapUpdate(b, 10_000, 1) 40 } 41 42 func BenchmarkTypesSmallWrites(b *testing.B) { 43 benchmarkTypesMapUpdate(b, 10_000, 1) 44 } 45 46 func BenchmarkProllyMediumWrites(b *testing.B) { 47 benchmarkProllyMapUpdate(b, 100_000, 1) 48 } 49 50 func BenchmarkTypesMediumWrites(b *testing.B) { 51 benchmarkTypesMapUpdate(b, 100_000, 1) 52 } 53 54 func BenchmarkProllyLargeWrites(b *testing.B) { 55 benchmarkProllyMapUpdate(b, 1_000_000, 1) 56 } 57 58 func benchmarkProllyMapUpdate(b *testing.B, size, k uint64) { 59 bench := generateProllyBench(b, size) 60 b.ReportAllocs() 61 b.ResetTimer() 62 63 b.Run("benchmark new format writes", func(b *testing.B) { 64 ctx := context.Background() 65 for i := 0; i < b.N; i++ { 66 mut := bench.m.Mutate() 67 for j := 0; j < int(k); j++ { 68 idx := rand.Uint64() % uint64(len(bench.tups)) 69 key := bench.tups[idx][0] 70 idx = rand.Uint64() % uint64(len(bench.tups)) 71 value := bench.tups[idx][0] 72 73 _ = mut.Put(ctx, key, value) 74 } 75 _, _ = mut.Map(ctx) 76 } 77 b.ReportAllocs() 78 }) 79 } 80 81 func benchmarkTypesMapUpdate(b *testing.B, size, k uint64) { 82 bench := generateTypesBench(b, size) 83 b.ResetTimer() 84 85 b.Run("benchmark old format writes", func(b *testing.B) { 86 ctx := context.Background() 87 for i := 0; i < b.N; i++ { 88 edit := bench.m.Edit() 89 for j := 0; j < int(k); j++ { 90 idx := rand.Uint64() % uint64(len(bench.tups)) 91 key := bench.tups[idx][0] 92 idx = rand.Uint64() % uint64(len(bench.tups)) 93 value := bench.tups[idx][0] 94 edit.Set(key, value) 95 } 96 _, _ = edit.Map(ctx) 97 } 98 b.ReportAllocs() 99 }) 100 }