Last active
May 15, 2016 02:32
-
-
Save GGist/c1d412b4f0c8c1a1062361d7157de085 to your computer and use it in GitHub Desktop.
Bencode Benchmark (bip_bencode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "bencode_bench" | |
version = "0.1.0" | |
[dependencies] | |
# Iterative | |
# bip_bencode = { path = "./bip_bencode", git = "https://github.com/GGist/bip-rs.git", rev = "dde80c8" } | |
# Recursive | |
bip_bencode = { path = "./bip_bencode", git = "https://github.com/GGist/bip-rs.git", rev = "f818512" } | |
[profile.bench] | |
opt-level = 3 | |
debug = false | |
rpath = false | |
lto = false | |
debug-assertions = false | |
codegen-units = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
extern crate bip_bencode; | |
extern crate test; | |
#[cfg(test)] | |
mod tests { | |
use std::fs::{File}; | |
use std::io::{Read}; | |
use bip_bencode::{Bencode}; | |
use test::{Bencher}; | |
#[bench] | |
fn deeply_nested_list(b: &mut Bencher) { | |
let nested_list = b"lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; | |
b.iter(|| Bencode::decode(nested_list).unwrap()); | |
} | |
#[bench] | |
fn two_kb_torrent(b: &mut Bencher) { | |
let mut file = File::open("INSERT TORRENT FILE PATH").unwrap(); | |
let mut contents = Vec::new(); | |
file.read_to_end(&mut contents).unwrap(); | |
b.iter(|| Bencode::decode(&contents).unwrap()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment