This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
forked from ETCDEVTeam/libsecp256k1-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignature.rs
46 lines (40 loc) · 1.48 KB
/
signature.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#![feature(test)]
extern crate test;
extern crate secp256k1;
extern crate secp256k1_test;
extern crate rand;
use test::Bencher;
use secp256k1::Signature;
use secp256k1_test::{Secp256k1, Message as SecpMessage};
use rand::thread_rng;
#[bench]
fn bench_signature_parse(b: &mut Bencher) {
let secp256k1 = Secp256k1::new();
let message_arr = [5u8; 32];
let (privkey, _) = secp256k1.generate_keypair(&mut thread_rng()).unwrap();
let message = SecpMessage::from_slice(&message_arr).unwrap();
let signature = secp256k1.sign(&message, &privkey).unwrap();
let signature_arr = signature.serialize_compact(&secp256k1);
assert!(signature_arr.len() == 64);
let mut signature_a = [0u8; 64];
signature_a.copy_from_slice(&signature_arr[0..64]);
b.iter(|| {
let _signature = Signature::parse(&signature_a);
});
}
#[bench]
fn bench_signature_serialize(b: &mut Bencher) {
let secp256k1 = Secp256k1::new();
let message_arr = [5u8; 32];
let (privkey, _) = secp256k1.generate_keypair(&mut thread_rng()).unwrap();
let message = SecpMessage::from_slice(&message_arr).unwrap();
let signature = secp256k1.sign(&message, &privkey).unwrap();
let signature_arr = signature.serialize_compact(&secp256k1);
assert!(signature_arr.len() == 64);
let mut signature_a = [0u8; 64];
signature_a.copy_from_slice(&signature_arr[0..64]);
let signature = Signature::parse(&signature_a);
b.iter(|| {
let _serialized = signature.serialize();
});
}