Skip to content

Instantly share code, notes, and snippets.

@yyforyongyu
Last active September 22, 2022 13:00
Show Gist options
  • Save yyforyongyu/5ee6e17c84c8ac64d325158241067705 to your computer and use it in GitHub Desktop.
Save yyforyongyu/5ee6e17c84c8ac64d325158241067705 to your computer and use it in GitHub Desktop.
a naive benchmark
package itest
import (
"fmt"
"time"
"github.com/lightningnetwork/lnd/lntest"
)
// testNetworkConnectionTimeout checks that the connectiontimeout is taking
// effect. It creates a node with a small connection timeout value, and
// connects it to a non-routable IP address.
// Results:
//
// [height:448] setup node :1.485320301s
// [height:448] restart node :832.921011ms
// ===========================================
// mine 10 blocks :305.289338ms
// setup a new node with 458 blocks: 1.722693468s
// restart node :831.285503ms
// ===========================================
// mine 100 blocks :5.899697955s
// setup a new node with 558 blocks: 2.345724038s
// restart node :831.945432ms
// ===========================================
// mine 1000 blocks :59.836386824s
// setup a new node with 1558 blocks: 20.319189488s
// restart node :834.446827ms
// ===========================================
// [height:1558] restart old node :835.327677ms
//
func testBenchmark(ht *lntest.HarnessTest) {
_, height := ht.GetBestBlock()
start := time.Now()
node := ht.NewNode("benchmark", nil)
fmt.Printf("[height:%d] setup node :%v\n", height, time.Since(start))
start = time.Now()
ht.RestartNode(node)
fmt.Printf("[height:%d] restart node :%v\n", height, time.Since(start))
fmt.Println("===========================================")
blocks := []uint32{10, 100, 1000}
for _, num := range blocks {
start := time.Now()
ht.MineBlocks(num)
fmt.Printf("mine %d blocks :%v\n", num, time.Since(start))
_, height := ht.GetBestBlock()
start = time.Now()
ben := ht.NewNode("benchmark", nil)
defer ht.Shutdown(ben)
fmt.Printf("setup node with %d blocks: %v\n", height, time.Since(start))
start = time.Now()
ht.RestartNode(ben)
fmt.Printf("restart node :%v\n", time.Since(start))
fmt.Println("===========================================")
}
_, height = ht.GetBestBlock()
start = time.Now()
ht.RestartNode(node)
ht.WaitForBlockchainSync(node)
fmt.Printf("[height:%d] restart node :%v\n", height, time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment