mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
bench: crypto/ecdsa.v
This commit is contained in:
parent
f7cc9d5daa
commit
c9a79ea026
44
bench/crypto/ecdsa/ecdsa.v
Normal file
44
bench/crypto/ecdsa/ecdsa.v
Normal file
@ -0,0 +1,44 @@
|
||||
import time
|
||||
import crypto.ecdsa
|
||||
|
||||
fn main() {
|
||||
iterations := 1000
|
||||
|
||||
println('Benchmarking key generation...')
|
||||
mut total_gen_time := i64(0)
|
||||
for _ in 0 .. iterations {
|
||||
sw := time.new_stopwatch()
|
||||
_, _ := ecdsa.generate_key() or { panic(err) }
|
||||
elapsed := sw.elapsed().microseconds()
|
||||
total_gen_time += elapsed
|
||||
}
|
||||
avg_gen_time := total_gen_time / iterations
|
||||
println('Average key generation time: ${avg_gen_time} µs')
|
||||
|
||||
pub_key, priv_key := ecdsa.generate_key() or { panic(err) }
|
||||
message := 'Benchmark message'.bytes()
|
||||
|
||||
println('Benchmarking signing...')
|
||||
mut total_sign_time := i64(0)
|
||||
for _ in 0 .. iterations {
|
||||
sw := time.new_stopwatch()
|
||||
_ := priv_key.sign(message) or { panic(err) }
|
||||
elapsed := sw.elapsed().microseconds()
|
||||
total_sign_time += elapsed
|
||||
}
|
||||
avg_sign_time := total_sign_time / iterations
|
||||
println('Average sign time: ${avg_sign_time} µs')
|
||||
|
||||
sig := priv_key.sign(message) or { panic(err) }
|
||||
|
||||
println('Benchmarking verification...')
|
||||
mut total_verify_time := i64(0)
|
||||
for _ in 0 .. iterations {
|
||||
sw := time.new_stopwatch()
|
||||
_ := pub_key.verify(message, sig) or { panic(err) }
|
||||
elapsed := sw.elapsed().microseconds()
|
||||
total_verify_time += elapsed
|
||||
}
|
||||
avg_verify_time := total_verify_time / iterations
|
||||
println('Average verify time: ${avg_verify_time} µs')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user