Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Sep 13, 2015
1 parent 5d7717a commit dd9b655
Show file tree
Hide file tree
Showing 16 changed files with 10,911 additions and 312 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ tags
target
*.lock
tmp
*.csv
*.fst
*-got
*.csv.idx
words
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ license = "Unlicense/MIT"
name = "fst"
path = "src/bin/main.rs"

[[bench]]
name = "build"
path = "./benches/build.rs"
test = false
bench = true

[dependencies]
byteorder = "*"

Expand Down
57 changes: 57 additions & 0 deletions benches/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![feature(test)]

extern crate fst;
extern crate test;

use std::collections::HashSet;

use fst::{Builder, Fst};
use test::Bencher;

const WORDS: &'static str = include_str!("./../data/words-10000");

fn get_words() -> Vec<String> {
WORDS.lines().map(|s| s.to_owned()).collect()
}

fn get_words_outputs() -> Vec<(String, u64)> {
WORDS.lines().map(|s| (s.to_owned(), s.len() as u64)).collect()
}

#[bench]
fn build_fst_set(b: &mut Bencher) {
let words = get_words();
b.bytes = WORDS.len() as u64;
b.iter(|| {
let mut bfst = Builder::memory();
for word in &words {
bfst.add(word).unwrap();
}
Fst::new(bfst.into_inner().unwrap()).unwrap();
});
}

#[bench]
fn build_fst_map(b: &mut Bencher) {
let words = get_words_outputs();
b.bytes = WORDS.len() as u64;
b.iter(|| {
let mut bfst = Builder::memory();
for &(ref word, len) in &words {
bfst.insert(word, len).unwrap();
}
Fst::new(bfst.into_inner().unwrap()).unwrap();
});
}

#[bench]
fn build_hash_set(b: &mut Bencher) {
let words = get_words();
b.bytes = WORDS.len() as u64;
b.iter(|| {
let mut set = HashSet::new();
for word in &words {
set.insert(word);
}
});
}
Loading

0 comments on commit dd9b655

Please sign in to comment.