github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/others/cgo/ec_bench/gonative.go (about) 1 package main 2 3 import ( 4 "encoding/hex" 5 "github.com/piotrnar/gocoin/lib/btc" 6 "runtime" 7 "sync" 8 "time" 9 ) 10 11 var CNT int = 100e3 12 13 func main() { 14 key, _ := hex.DecodeString("040eaebcd1df2df853d66ce0e1b0fda07f67d1cabefde98514aad795b86a6ea66dbeb26b67d7a00e2447baeccc8a4cef7cd3cad67376ac1c5785aeebb4f6441c16") 15 sig, _ := hex.DecodeString("3045022100fe00e013c244062847045ae7eb73b03fca583e9aa5dbd030a8fd1c6dfcf11b1002207d0d04fed8fa1e93007468d5a9e134b0a7023b6d31db4e50942d43a250f4d07c01") 16 msg, _ := hex.DecodeString("3382219555ddbb5b00e0090f469e590ba1eae03c7f28ab937de330aa60294ed6") 17 var wg sync.WaitGroup 18 max_routines := make(chan bool, 2*runtime.NumCPU()) 19 println("Number of threads:", cap(max_routines)) 20 sta := time.Now() 21 for i := 0; i < CNT; i++ { 22 wg.Add(1) 23 max_routines <- true 24 go func() { 25 if !btc.EcdsaVerify(key, sig, msg) { 26 println("Verify error") 27 } 28 wg.Done() 29 <-max_routines 30 }() 31 } 32 wg.Wait() 33 sto := time.Now() 34 println((sto.UnixNano()-sta.UnixNano())/int64(CNT), "ns per ECDSA_Verify") 35 }