Skip to content

Commit 2fc1fb4

Browse files
committed
tests: Add a benchmark for Delimiters::from_byte
1 parent 64a2d76 commit 2fc1fb4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl Delimiters {
313313
}
314314

315315
#[inline]
316-
fn from_byte(byte: Option<u8>) -> Delimiters {
316+
pub(crate) fn from_byte(byte: Option<u8>) -> Delimiters {
317317
const TABLE: [Delimiters; 255] = {
318318
let mut table = [Delimiter::None; 255];
319319
table[b';' as usize] = Delimiter::Semicolon;

src/tests.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use encoding_rs;
99
use serde_json::{self, json, Map, Value};
1010

1111
use crate::color::{parse_color_with, FromParsedColor};
12-
use crate::{ColorParser, PredefinedColorSpace};
12+
use crate::{ColorParser, PredefinedColorSpace, Delimiters};
1313

1414
#[cfg(feature = "bench")]
1515
use self::test::Bencher;
@@ -922,6 +922,18 @@ impl<'a> ToJson for CowRcStr<'a> {
922922
}
923923
}
924924

925+
#[bench]
926+
#[cfg(feature = "bench")]
927+
fn delimiter_from_byte(b: &mut Bencher) {
928+
b.iter(|| {
929+
for _ in 0..1000 {
930+
for i in 0..255 {
931+
std::hint::black_box(Delimiters::from_byte(Some(i as u8)));
932+
}
933+
}
934+
})
935+
}
936+
925937
#[cfg(feature = "bench")]
926938
const BACKGROUND_IMAGE: &'static str = include_str!("big-data-url.css");
927939

0 commit comments

Comments
 (0)