v / vlib / x / crypto / ascon / bench / sum.v
36 lines · 32 sloc · 913 bytes · a10c59704b4fd795accd3542aed10e131d050ec4
Raw
1import time
2import x.crypto.ascon
3
4// Before:
5// Benchmarking ascon.sum256 ...
6// Average ascon.sum256 time: 8 µs
7// Benchmarking ascon.sum256 ...
8// Average ascon.sum256 time: 6 µs
9
10// For xof128 (32 bytes)
11// Benchmarking ascon.xof128 ...
12// Average ascon.xof128 time: 7 µs
13// Benchmarking ascon.xof128 ...
14// Average ascon.xof128 time: 6 µs
15
16// For cxof128 32 bytes
17// Benchmarking ascon.cxof128 ...
18// Average ascon.cxof128 time: 9 µs
19// Benchmarking ascon.sum256 ...
20// Average ascon.cxof128 time: 7 µs
21//
22fn main() {
23 iterations := 1000
24 msg := [u8(0xff)].repeat(100)
25
26 println('Benchmarking ascon.sum256 ...')
27 mut total_sum_time := i64(0)
28 for _ in 0 .. iterations {
29 sw := time.new_stopwatch()
30 _ := ascon.sum256(msg)
31 elapsed := sw.elapsed().microseconds()
32 total_sum_time += elapsed
33 }
34 avg_sum_time := total_sum_time / iterations
35 println('Average ascon.sum256 time: ${avg_sum_time} µs')
36}
37