mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 10:20:44 +00:00
eth/filters: replace fmt.Println with b.Log in tests (#19670)
This commit is contained in:
parent
65b48159d1
commit
7cffa1d0aa
1 changed files with 14 additions and 14 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -28,6 +27,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/bitutil"
|
"github.com/XinFinOrg/XDPoSChain/common/bitutil"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/bloombits"
|
"github.com/XinFinOrg/XDPoSChain/core/bloombits"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/event"
|
"github.com/XinFinOrg/XDPoSChain/event"
|
||||||
|
|
@ -66,7 +66,7 @@ const benchFilterCnt = 2000
|
||||||
|
|
||||||
func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
||||||
benchDataDir := node.DefaultDataDir() + "/geth/chaindata"
|
benchDataDir := node.DefaultDataDir() + "/geth/chaindata"
|
||||||
fmt.Println("Running bloombits benchmark section size:", sectionSize)
|
b.Log("Running bloombits benchmark section size:", sectionSize)
|
||||||
|
|
||||||
db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "")
|
db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -78,7 +78,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearBloomBits(db)
|
clearBloomBits(db)
|
||||||
fmt.Println("Generating bloombits data...")
|
b.Log("Generating bloombits data...")
|
||||||
headNum := core.GetBlockNumber(db, head)
|
headNum := core.GetBlockNumber(db, head)
|
||||||
if headNum < sectionSize+512 {
|
if headNum < sectionSize+512 {
|
||||||
b.Fatalf("not enough blocks for running a benchmark")
|
b.Fatalf("not enough blocks for running a benchmark")
|
||||||
|
|
@ -113,16 +113,16 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
||||||
core.WriteBloomBits(db, uint(i), sectionIdx, sectionHead, comp)
|
core.WriteBloomBits(db, uint(i), sectionIdx, sectionHead, comp)
|
||||||
}
|
}
|
||||||
//if sectionIdx%50 == 0 {
|
//if sectionIdx%50 == 0 {
|
||||||
// fmt.Println(" section", sectionIdx, "/", cnt)
|
// b.Log(" section", sectionIdx, "/", cnt)
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
d := time.Since(start)
|
d := time.Since(start)
|
||||||
fmt.Println("Finished generating bloombits data")
|
b.Log("Finished generating bloombits data")
|
||||||
fmt.Println(" ", d, "total ", d/time.Duration(cnt*sectionSize), "per block")
|
b.Log(" ", d, "total ", d/time.Duration(cnt*sectionSize), "per block")
|
||||||
fmt.Println(" data size:", dataSize, " compressed size:", compSize, " compression ratio:", float64(compSize)/float64(dataSize))
|
b.Log(" data size:", dataSize, " compressed size:", compSize, " compression ratio:", float64(compSize)/float64(dataSize))
|
||||||
|
|
||||||
fmt.Println("Running filter benchmarks...")
|
b.Log("Running filter benchmarks...")
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
mux := new(event.TypeMux)
|
mux := new(event.TypeMux)
|
||||||
var backend *testBackend
|
var backend *testBackend
|
||||||
|
|
@ -142,8 +142,8 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d = time.Since(start)
|
d = time.Since(start)
|
||||||
fmt.Println("Finished running filter benchmarks")
|
b.Log("Finished running filter benchmarks")
|
||||||
fmt.Println(" ", d, "total ", d/time.Duration(benchFilterCnt), "per address", d*time.Duration(1000000)/time.Duration(benchFilterCnt*cnt*sectionSize), "per million blocks")
|
b.Log(" ", d, "total ", d/time.Duration(benchFilterCnt), "per address", d*time.Duration(1000000)/time.Duration(benchFilterCnt*cnt*sectionSize), "per million blocks")
|
||||||
db.Close()
|
db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ func clearBloomBits(db ethdb.Database) {
|
||||||
|
|
||||||
func BenchmarkNoBloomBits(b *testing.B) {
|
func BenchmarkNoBloomBits(b *testing.B) {
|
||||||
benchDataDir := node.DefaultDataDir() + "/geth/chaindata"
|
benchDataDir := node.DefaultDataDir() + "/geth/chaindata"
|
||||||
fmt.Println("Running benchmark without bloombits")
|
b.Log("Running benchmark without bloombits")
|
||||||
db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "")
|
db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("error opening database at %v: %v", benchDataDir, err)
|
b.Fatalf("error opening database at %v: %v", benchDataDir, err)
|
||||||
|
|
@ -188,14 +188,14 @@ func BenchmarkNoBloomBits(b *testing.B) {
|
||||||
|
|
||||||
clearBloomBits(db)
|
clearBloomBits(db)
|
||||||
|
|
||||||
fmt.Println("Running filter benchmarks...")
|
b.Log("Running filter benchmarks...")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
mux := new(event.TypeMux)
|
mux := new(event.TypeMux)
|
||||||
backend := &testBackend{mux, db, 0, new(event.Feed), new(event.Feed), new(event.Feed), new(event.Feed)}
|
backend := &testBackend{mux, db, 0, new(event.Feed), new(event.Feed), new(event.Feed), new(event.Feed)}
|
||||||
filter := NewRangeFilter(backend, 0, int64(headNum), []common.Address{{}}, nil)
|
filter := NewRangeFilter(backend, 0, int64(headNum), []common.Address{{}}, nil)
|
||||||
filter.Logs(context.Background())
|
filter.Logs(context.Background())
|
||||||
d := time.Since(start)
|
d := time.Since(start)
|
||||||
fmt.Println("Finished running filter benchmarks")
|
b.Log("Finished running filter benchmarks")
|
||||||
fmt.Println(" ", d, "total ", d*time.Duration(1000000)/time.Duration(headNum+1), "per million blocks")
|
b.Log(" ", d, "total ", d*time.Duration(1000000)/time.Duration(headNum+1), "per million blocks")
|
||||||
db.Close()
|
db.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue