Skip to content

Commit

Permalink
tests(null-filter): added benchmark
Browse files Browse the repository at this point in the history
Also renamed test-related files to match their purpose a bit better.
  • Loading branch information
Byron committed May 7, 2015
1 parent e489bff commit 43a1119
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions benches/lexer.rs → benches/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate json_tools;
extern crate test;

use json_tools::{Lexer};
use json_tools::{Lexer, FilterNull};

const NULL_RIDDEN: &'static str = r##"
{
Expand Down Expand Up @@ -113,12 +113,25 @@ const NULL_RIDDEN: &'static str = r##"
"##;

#[bench]
fn name(b: &mut test::Bencher) {
fn lexer_throughput_in_bytes(b: &mut test::Bencher) {
b.iter(|| {
let it = Lexer::new(NULL_RIDDEN.chars());
for t in it {
test::black_box(t);
}
});
b.bytes = NULL_RIDDEN.len() as u64;
}



#[bench]
fn filter_null_throughput_in_bytes(b: &mut test::Bencher) {
b.iter(|| {
let f = FilterNull::new(Lexer::new(NULL_RIDDEN.chars()));
for t in f {
test::black_box(t);
}
});
b.bytes = NULL_RIDDEN.len() as u64;
}
2 changes: 1 addition & 1 deletion tests/iterator.rs → tests/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ use json_tools::{Lexer, FilterNull};
fn filter_null_values() {
let src = r#"{"s":null, "v":true, "s":null }"#;
assert_eq!(Lexer::new(src.chars()).count(), 13);
assert_eq!(FilterNull::new(Lexer::new(src.chars())).count(), 5);
assert_eq!(FilterNull::new(Lexer::new(src.chars())).count(), 6);
}

0 comments on commit 43a1119

Please sign in to comment.