Move benches to a folder + add license

This commit is contained in:
Vincent Prouillet 2015-11-02 21:15:45 +00:00
parent 2057a0ac1f
commit 96acf8f143
5 changed files with 62 additions and 26 deletions

View File

@ -15,3 +15,8 @@ rust-crypto = "0.2.34"
[features]
default = []
dev = ["clippy"]
[profile.bench]
lto = true
codegen-units = 1
opt-level = 3

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Vincent Prouillet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -33,7 +33,7 @@ Right now, only SHA256 is supported.
The header is currently not customisable and therefore does not support things like kid right now.
## Performance
On my thinkpad 440s:
On my thinkpad 440s for a 2 claims struct:
```
test tests::bench_decode ... bench: 5,578 ns/iter (+/- 307)

35
benches/jwt.rs Normal file
View File

@ -0,0 +1,35 @@
#![feature(test)]
extern crate test;
extern crate jwt;
extern crate rustc_serialize;
use rustc_serialize::{Encodable};
use jwt::{encode, decode, Algorithm};
#[derive(Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
struct Claims {
sub: String,
company: String
}
#[bench]
fn bench_encode(b: &mut test::Bencher) {
b.iter(|| encode::<Claims>(
Claims {
sub: "b@b.com".to_owned(),
company: "ACME".to_owned()
},
"secret".to_owned(),
Algorithm::HS256
));
}
#[bench]
fn bench_decode(b: &mut test::Bencher) {
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ".to_owned();
b.iter(|| decode::<Claims>(
token.clone(),
"secret".to_owned(),
Algorithm::HS256
));
}

View File

@ -5,10 +5,8 @@
#![cfg_attr(feature = "dev", feature(plugin))]
#![cfg_attr(feature = "dev", plugin(clippy))]
#![feature(test)]
extern crate rustc_serialize;
extern crate crypto;
extern crate test;
use rustc_serialize::{json, Encodable, Decodable};
use rustc_serialize::base64::{self, ToBase64, FromBase64};
@ -129,7 +127,6 @@ pub fn decode<T: Part>(token: String, secret: String, algorithm: Algorithm) -> R
#[cfg(test)]
mod tests {
use super::{encode, decode, Algorithm, Header, Part, sign, verify};
use test::Bencher;
#[derive(Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
struct Claims {
@ -198,26 +195,4 @@ mod tests {
let claims = decode::<Claims>(token.to_owned(), "secret".to_owned(), Algorithm::HS256);
assert_eq!(claims.is_ok(), false);
}
#[bench]
fn bench_encode(b: &mut Bencher) {
b.iter(|| encode::<Claims>(
Claims {
sub: "b@b.com".to_owned(),
company: "ACME".to_owned()
},
"secret".to_owned(),
Algorithm::HS256
));
}
#[bench]
fn bench_decode(b: &mut Bencher) {
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ".to_owned();
b.iter(|| decode::<Claims>(
token.clone(),
"secret".to_owned(),
Algorithm::HS256
));
}
}