From 96acf8f1432acf52cc57a41ad9741e32c8da356e Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 2 Nov 2015 21:15:45 +0000 Subject: [PATCH] Move benches to a folder + add license --- Cargo.toml | 5 +++++ LICENSE | 21 +++++++++++++++++++++ README.md | 2 +- benches/jwt.rs | 35 +++++++++++++++++++++++++++++++++++ src/lib.rs | 25 ------------------------- 5 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 LICENSE create mode 100644 benches/jwt.rs diff --git a/Cargo.toml b/Cargo.toml index 32f40b8..b858fc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,8 @@ rust-crypto = "0.2.34" [features] default = [] dev = ["clippy"] + +[profile.bench] +lto = true +codegen-units = 1 +opt-level = 3 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..36272c3 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index d0e47ef..8048d44 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/benches/jwt.rs b/benches/jwt.rs new file mode 100644 index 0000000..409fe6e --- /dev/null +++ b/benches/jwt.rs @@ -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 { + 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::( + token.clone(), + "secret".to_owned(), + Algorithm::HS256 + )); +} diff --git a/src/lib.rs b/src/lib.rs index f551d14..9cb3740 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(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::(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 { - 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::( - token.clone(), - "secret".to_owned(), - Algorithm::HS256 - )); - } }