File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( test) ]
2
+ #![ cfg( feature = "alloc" ) ]
3
+
4
+ extern crate test;
5
+
6
+ use spki:: SubjectPublicKeyInfoRef ;
7
+ use test:: { Bencher , black_box} ;
8
+
9
+ /// Ed25519 `SubjectPublicKeyInfo` encoded as ASN.1 DER
10
+ const ED25519_DER_EXAMPLE : & [ u8 ] = include_bytes ! ( "../tests/examples/ed25519-pub.der" ) ;
11
+
12
+ #[ bench]
13
+ fn bench_spki_decode ( b : & mut Bencher ) {
14
+ b. iter ( || {
15
+ let pk_encoded = black_box ( ED25519_DER_EXAMPLE ) ;
16
+ black_box ( SubjectPublicKeyInfoRef :: try_from ( pk_encoded) ) . unwrap ( ) ;
17
+ } ) ;
18
+ b. bytes = ED25519_DER_EXAMPLE . len ( ) as u64 ;
19
+ }
20
+
21
+ #[ bench]
22
+ fn bench_spki_encode ( b : & mut Bencher ) {
23
+ let pk = SubjectPublicKeyInfoRef :: try_from ( ED25519_DER_EXAMPLE ) . unwrap ( ) ;
24
+ let mut buf = [ 0u8 ; 256 ] ;
25
+
26
+ use der:: Encode ;
27
+ b. iter ( || {
28
+ let pk = black_box ( & pk) ;
29
+ black_box ( pk. encode_to_slice ( & mut buf) ) . unwrap ( ) ;
30
+ } ) ;
31
+ b. bytes = ED25519_DER_EXAMPLE . len ( ) as u64 ;
32
+ }
You can’t perform that action at this time.
0 commit comments