Skip to content

Instantly share code, notes, and snippets.

@GGist
Last active May 15, 2016 02:32
Show Gist options
  • Save GGist/c1d412b4f0c8c1a1062361d7157de085 to your computer and use it in GitHub Desktop.
Save GGist/c1d412b4f0c8c1a1062361d7157de085 to your computer and use it in GitHub Desktop.
Bencode Benchmark (bip_bencode)
[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
#![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