Add dbgStats metrics
Add dbgStats metrics to analyze number of Hashes, db Gets, and db Puts.
Current benchmarks:
```
CASE A, AddBatch was 8.841700 times faster than without AddBatch
nCPU: 4, nLeafs: 1024, hash: Poseidon, db: memory
dbgStats(hash: 2.044k, dbGet: 1, dbPut: 2.049k)
CASE B, AddBatch was 7.678766 times faster than without AddBatch
nCPU: 4, nLeafs: 1024, hash: Poseidon, db: memory
dbgStats(hash: 2.044k, dbGet: 199, dbPut: 2.049k)
CASE C, AddBatch was 8.401087 times faster than without AddBatch
nCPU: 4, nLeafs: 1024, hash: Poseidon, db: memory
dbgStats(hash: 2.044k, dbGet: 207, dbPut: 2.049k)
CASE D, AddBatch was 2.466346 times faster than without AddBatch
nCPU: 4, nLeafs: 4096, hash: Poseidon, db: memory
dbgStats(hash: 33.884k, dbGet: 30.697k, dbPut: 33.889k)
CASE E, AddBatch was 1.958160 times faster than without AddBatch
nCPU: 4, nLeafs: 4096, hash: Poseidon, db: memory
dbgStats(hash: 41.419k, dbGet: 37.558k, dbPut: 41.874k)
TestAddBatchBench: nCPU: 4, nLeafs: 50000, hash: Blake2b, db: leveldb
Add loop: 10.089858449s
dbgStats(hash: 825.285k, dbGet: 788.869k, dbPut: 925.285k)
AddBatch: 904.647829ms
dbgStats(hash: 122.458k, dbGet: 1, dbPut: 122.463k)
TestDbgStats
add in loop dbgStats(hash: 141.915k, dbGet: 134.602k, dbPut: 161.915k)
addbatch caseA dbgStats(hash: 24.528k, dbGet: 1, dbPut: 24.533k)
addbatch caseD dbgStats(hash: 115.506k, dbGet: 97.482k, dbPut: 115.516k)
```
3 years ago |
|
package arbo
import "fmt"
// dbgStats is for debug purposes
type dbgStats struct { hash int dbGet int dbPut int }
func (t *Tree) dbgInit() { t.dbg = newDbgStats() }
func newDbgStats() *dbgStats { return &dbgStats{ hash: 0, dbGet: 0, dbPut: 0, } }
func (d *dbgStats) incHash() { if d == nil { return } d.hash++ }
func (d *dbgStats) incDbGet() { if d == nil { return } d.dbGet++ }
func (d *dbgStats) incDbPut() { if d == nil { return } d.dbPut++ }
func (d *dbgStats) add(d2 *dbgStats) { if d == nil || d2 == nil { return } d.hash += d2.hash d.dbGet += d2.dbGet d.dbPut += d2.dbPut }
func (d *dbgStats) print(prefix string) { if d == nil { return } fmt.Printf("%sdbgStats(hash: %s, dbGet: %s, dbPut: %s)\n", prefix, formatK(d.hash), formatK(d.dbGet), formatK(d.dbPut)) }
func formatK(v int) string { if v/1000 > 0 { return fmt.Sprintf("%.3fk", float64(v)/1000) //nolint:gomnd
} return fmt.Sprintf("%d", v) }
|