Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmark to reuse parsers #11

Merged
merged 2 commits into from
Jun 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use black_box in benchmarks
Make sure that result values are not optimised away.
RReverser committed Jun 22, 2018
commit 5df9c4ae2cc01c4a8d6afb07fb7e36c821cc18e4
14 changes: 7 additions & 7 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ extern crate test;
extern crate uap_rust;
extern crate woothee;

use test::Bencher;
use test::{Bencher, black_box};
use uap_rust::parser as uap;
use woothee::parser as woo;

@@ -16,15 +16,15 @@ lazy_static! {
}

fn b_uap() {
let _ = UAP_PARSER.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)".to_string());
let _ = UAP_PARSER.parse("Twitterbot/1.0".to_string());
let _ = UAP_PARSER.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)".to_string());
black_box(UAP_PARSER.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)".to_string()));
black_box(UAP_PARSER.parse("Twitterbot/1.0".to_string()));
black_box(UAP_PARSER.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)".to_string()));
}

fn b_woothee() {
let _ = WOO_PARSER.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
let _ = WOO_PARSER.parse("Twitterbot/1.0");
let _ = WOO_PARSER.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)");
black_box(WOO_PARSER.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"));
black_box(WOO_PARSER.parse("Twitterbot/1.0"));
black_box(WOO_PARSER.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)"));
}

#[bench]