Skip to content

Commit 4972950

Browse files
committed
test: Add a benchmark for parsing unquoted data uris.
Current values: test tests::unquoted_url ... bench: 580,075 ns/iter (+/- 15,881)
1 parent b778697 commit 4972950

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/big-data-url.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![crate_name = "cssparser"]
66
#![crate_type = "rlib"]
77

8+
#![feature(test)]
89
#![deny(missing_docs)]
910

1011
/*!

src/tests.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
extern crate test;
6+
57
use std::borrow::Cow::{self, Borrowed};
68
use std::fs::File;
79
use std::io::{self, Write};
810
use std::path::Path;
911
use std::process::Command;
1012
use rustc_serialize::json::{self, Json, ToJson};
1113
use tempdir::TempDir;
14+
use self::test::Bencher;
1215

1316
use encoding::label::encoding_from_whatwg_label;
1417

@@ -576,6 +579,22 @@ impl ToJson for Color {
576579
}
577580
}
578581

582+
const BACKGROUND_IMAGE: &'static str = include_str!("big-data-url.css");
583+
584+
#[bench]
585+
fn unquoted_url(b: &mut Bencher) {
586+
b.iter(|| {
587+
let mut input = Parser::new(BACKGROUND_IMAGE);
588+
input.look_for_var_functions();
589+
590+
let result = input.try(|input| input.expect_url());
591+
592+
assert!(result.is_ok());
593+
594+
input.seen_var_functions();
595+
(result.is_ok(), input.seen_var_functions())
596+
})
597+
}
579598

580599
struct JsonParser;
581600

@@ -667,7 +686,6 @@ fn component_values_to_json(input: &mut Parser) -> Vec<Json> {
667686
values
668687
}
669688

670-
671689
fn one_component_value_to_json(token: Token, input: &mut Parser) -> Json {
672690
fn numeric(value: NumericValue) -> Vec<json::Json> {
673691
vec![

0 commit comments

Comments
 (0)