forked from michaelsproul/rust_radix_trie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic criterion benches, update to 2018 version. (michaelsproul#52)
- Loading branch information
1 parent
5e4d720
commit 3cb95fd
Showing
14 changed files
with
10,426 additions
and
29 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "radix_trie" | ||
version = "0.1.5" | ||
description = "Generic radix trie data-structure." | ||
|
||
edition = "2018" | ||
license = "MIT" | ||
authors = ["Michael Sproul <[email protected]>"] | ||
|
||
|
@@ -19,9 +19,17 @@ endian-type = "0.1.2" | |
serde = { version = "1.0", optional = true } | ||
|
||
[dev-dependencies] | ||
criterion = "0.3" | ||
quickcheck = "0.4" | ||
rand = "0.3" | ||
serde_test = "1.0" | ||
|
||
[[bench]] | ||
name = "trie_benches" | ||
harness = false | ||
|
||
[lib] | ||
bench = false | ||
|
||
[badges] | ||
travis-ci = { repository = "michaelsproul/rust_radix_trie" } |
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,60 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use radix_trie::Trie; | ||
|
||
fn get_text() -> Vec<String> { | ||
use std::fs::File; | ||
use std::io::Read; | ||
const DATA: &[&str] = &["data/1984.txt", "data/sun-rising.txt"]; | ||
let mut contents = String::new(); | ||
File::open(&DATA[1]) | ||
.unwrap() | ||
.read_to_string(&mut contents) | ||
.unwrap(); | ||
contents | ||
.split(|c: char| c.is_whitespace()) | ||
.map(|s| s.to_string()) | ||
.collect() | ||
} | ||
|
||
fn make_trie(words: &[String]) -> Trie<&str, usize> { | ||
let mut trie = Trie::new(); | ||
for w in words { | ||
trie.insert(&w[..], w.len()); | ||
} | ||
trie | ||
} | ||
|
||
fn trie_insert(b: &mut Criterion) { | ||
let words = get_text(); | ||
b.bench_function("trie insert", |b| b.iter(|| make_trie(&words))); | ||
} | ||
|
||
fn trie_get(b: &mut Criterion) { | ||
let words = get_text(); | ||
let trie = make_trie(&words); | ||
b.bench_function("trie get", |b| { | ||
b.iter(|| { | ||
words | ||
.iter() | ||
.map(|w| trie.get(&&w[..])) | ||
.collect::<Vec<Option<&usize>>>() | ||
}) | ||
}); | ||
} | ||
|
||
fn trie_insert_remove(b: &mut Criterion) { | ||
let words = get_text(); | ||
|
||
b.bench_function("trie remove", |b| { | ||
b.iter(|| { | ||
let mut trie = make_trie(&words); | ||
for w in &words { | ||
trie.remove(&&w[..]); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, trie_insert, trie_get, trie_insert_remove); | ||
|
||
criterion_main!(benches); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
BUSY old fool, unruly Sun, | ||
Why dost thou thus, | ||
Through windows, and through curtains, call on us ? | ||
Must to thy motions lovers' seasons run ? | ||
Saucy pedantic wretch, go chide | ||
Late school-boys and sour prentices, | ||
Go tell court-huntsmen that the king will ride, | ||
Call country ants to harvest offices ; | ||
Love, all alike, no season knows nor clime, | ||
Nor hours, days, months, which are the rags of time. | ||
|
||
Thy beams so reverend, and strong | ||
Why shouldst thou think ? | ||
I could eclipse and cloud them with a wink, | ||
But that I would not lose her sight so long. | ||
If her eyes have not blinded thine, | ||
Look, and to-morrow late tell me, | ||
Whether both th' Indias of spice and mine | ||
Be where thou left'st them, or lie here with me. | ||
Ask for those kings whom thou saw'st yesterday, | ||
And thou shalt hear, "All here in one bed lay." | ||
|
||
She's all states, and all princes I ; | ||
Nothing else is ; | ||
Princes do but play us ; compared to this, | ||
All honour's mimic, all wealth alchemy. | ||
Thou, Sun, art half as happy as we, | ||
In that the world's contracted thus ; | ||
Thine age asks ease, and since thy duties be | ||
To warm the world, that's done in warming us. | ||
Shine here to us, and thou art everywhere ; | ||
This bed thy center is, these walls thy sphere. |
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
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
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
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
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