Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openssl and rust-crypto to benchmark #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 104 additions & 2 deletions bench/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
[dependencies]
sha1 = { path = ".." }
ring = "*"
openssl = "*"
rust-crypto = "*"

[[bin]]
name = "bench"
Expand Down
28 changes: 26 additions & 2 deletions bench/bench.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
extern crate sha1;
extern crate ring;
extern crate openssl;
extern crate crypto;

use std::env;
use std::fs;
use std::io::{Read, Write};
use std::time::{Instant, Duration};
use std::process::{Command, Stdio};

use crypto::digest::Digest;

fn time<F, FMT>(desc: &str, f: F, fmt: FMT)
where F: Fn(),
FMT: Fn(Duration) -> String
Expand All @@ -17,6 +21,11 @@ fn time<F, FMT>(desc: &str, f: F, fmt: FMT)
println!("{}: {}", desc, fmt(duration));
}

fn to_hex(bytes : &[u8]) -> String {
let hex_bytes : Vec<String> = bytes.iter().map(|b| format!("{:02x}", b)).collect();
hex_bytes.join("")
}

fn main() {
let args: Vec<_> = env::args().collect();
let mut out = Vec::<u8>::new();
Expand Down Expand Up @@ -55,14 +64,29 @@ fn main() {
|| {
let mut sha1 = sha1::Sha1::new();
sha1.update(&out);
println!("{}", sha1.digest());
println!("sha1: {}", sha1.digest());
},
&throughput);

time("ring crate",
|| {
let digest = ring::digest::digest(&ring::digest::SHA1, &out);
println!("{:?}", digest);
println!("ring: {:?}", digest);
},
&throughput);

time("openssl crate", || {
let digest = openssl::sha::sha1(&out);
println!("openssl: {}", to_hex(&digest));
},
&throughput);

time("crypto crate",
|| {
let mut hasher = crypto::sha1::Sha1::new();
hasher.input(&out);
let digest = hasher.result_str();
println!("crypto: {}", digest);
},
&throughput);
}