github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/others/cgo/ec_bench/sipasec.go (about) 1 package main 2 3 import ( 4 "encoding/hex" 5 "github.com/piotrnar/gocoin/lib/others/cgo/sipasec" 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 sipasec.EC_Verify(key, sig, msg) != 1 { 26 println("Verify error") 27 return 28 } 29 wg.Done() 30 <-max_routines 31 }() 32 } 33 wg.Wait() 34 sto := time.Now() 35 println((sto.UnixNano()-sta.UnixNano())/int64(CNT), "ns per ECDSA_Verify") 36 }