-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d7717a
commit dd9b655
Showing
16 changed files
with
10,911 additions
and
312 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ tags | |
target | ||
*.lock | ||
tmp | ||
*.csv | ||
*.fst | ||
*-got | ||
*.csv.idx | ||
words |
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
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
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); | ||
} | ||
}); | ||
} |
Oops, something went wrong.