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 all commits
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
23 changes: 14 additions & 9 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#![feature(test)]

#[macro_use]
extern crate lazy_static;
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;

lazy_static! {
static ref UAP_PARSER: uap::Parser = uap::Parser::new().unwrap();
static ref WOO_PARSER: woo::Parser = woo::Parser::new();
}

fn b_uap() {
let parser = uap::Parser::new().unwrap();
let _ = parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)".to_string());
let _ = parser.parse("Twitterbot/1.0".to_string());
let _ = 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 parser = woo::Parser::new();
let _ = parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
let _ = parser.parse("Twitterbot/1.0");
let _ = 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]