Skip to content

Remove Python-generated binary search and use match for color keywords #32

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

Merged
merged 2 commits into from
Dec 10, 2013
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
Next Next commit
Add some keyword color lookup benchmarks.
  • Loading branch information
SimonSapin committed Dec 10, 2013
commit 22a94c2443b0afd156ac1288e14f61e91c728dba
22 changes: 22 additions & 0 deletions tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::rt::io;
use std::rt::io::Writer;
use extra::{tempfile, json};
use extra::json::ToJson;
use extra::test;

use super::*;
use ast::*;
Expand Down Expand Up @@ -168,6 +169,27 @@ fn color3_keywords() {
}


#[bench]
fn bench_color_lookup_red(b: &mut test::BenchHarness) {
let ident = parse_one_component_value(tokenize("red")).unwrap();
b.iter(|| assert!(Color::parse(&ident).is_some()));
}


#[bench]
fn bench_color_lookup_lightgoldenrodyellow(b: &mut test::BenchHarness) {
let ident = parse_one_component_value(tokenize("lightgoldenrodyellow")).unwrap();
b.iter(|| assert!(Color::parse(&ident).is_some()));
}


#[bench]
fn bench_color_lookup_fail(b: &mut test::BenchHarness) {
let ident = parse_one_component_value(tokenize("lightgoldenrodyellowbazinga")).unwrap();
b.iter(|| assert!(Color::parse(&ident).is_none()));
}


#[test]
fn nth() {
do run_json_tests(include_str!("css-parsing-tests/An+B.json")) |input| {
Expand Down