Add Allocation Data To Benchmark (#12641)

* add more data

* terence's review
This commit is contained in:
Nishant Das 2023-07-20 16:49:17 +08:00 committed by GitHub
parent 056d3ff0cc
commit 945c76132c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"runtime"
"strings" "strings"
"time" "time"
@ -286,11 +287,16 @@ func benchmarkHash(sszPath string, sszType string) {
log.Fatal(err) log.Fatal(err)
} }
start := time.Now() start := time.Now()
stat := &runtime.MemStats{}
runtime.ReadMemStats(stat)
root, err := stateTrieState.HashTreeRoot(context.Background()) root, err := stateTrieState.HashTreeRoot(context.Background())
if err != nil { if err != nil {
log.Fatal("couldn't hash") log.Fatal("couldn't hash")
} }
newStat := &runtime.MemStats{}
runtime.ReadMemStats(newStat)
fmt.Printf("Deserialize Duration: %v, Hashing Duration: %v HTR: %#x\n", deserializeDuration, time.Since(start), root) fmt.Printf("Deserialize Duration: %v, Hashing Duration: %v HTR: %#x\n", deserializeDuration, time.Since(start), root)
fmt.Printf("Total Memory Allocation Differential: %d bytes, Heap Memory Allocation Differential: %d bytes\n", int64(newStat.TotalAlloc)-int64(stat.TotalAlloc), int64(newStat.HeapAlloc)-int64(stat.HeapAlloc))
return return
default: default:
log.Fatal("Invalid type") log.Fatal("Invalid type")