-
Notifications
You must be signed in to change notification settings - Fork 595
Open
Description
It would be nice to have performance of DateTime::parse_from_rfc3339 method match performance of speedate::DateTime::parse_str_rfc3339
Naively looking at both implementations the difference seems to come from avoiding bounds checking and unrolling scan::number loops
Lines 192 to 196 in f3fd15f
| parsed.set_year(try_consume!(scan::number(s, 4, 4)))?; | |
| s = scan::char(s, b'-')?; | |
| parsed.set_month(try_consume!(scan::number(s, 2, 2)))?; | |
| s = scan::char(s, b'-')?; | |
| parsed.set_day(try_consume!(scan::number(s, 2, 2)))?; |
if bytes.len() < 10 {
return Err(ParseError::TooShort);
}
let year: u16;
let month: u8;
let day: u8;
unsafe {
let y1 = get_digit_unchecked!(bytes, 0, InvalidCharYear) as u16;
let y2 = get_digit_unchecked!(bytes, 1, InvalidCharYear) as u16;
let y3 = get_digit_unchecked!(bytes, 2, InvalidCharYear) as u16;
let y4 = get_digit_unchecked!(bytes, 3, InvalidCharYear) as u16;
year = y1 * 1000 + y2 * 100 + y3 * 10 + y4;
match bytes.get_unchecked(4) {
b'-' => (),
_ => return Err(ParseError::InvalidCharDateSep),
}Perhaps someone with more insight will correct me and actually the difference comes from Parsed struct or something like that.
I can write some microbenchmarks if this is something anyone is willing to look into
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels