-
Notifications
You must be signed in to change notification settings - Fork 10
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
Slower than std? #24
Comments
This crate comes with a criterion benchmark suite. I would suggest to check out the repostiory and run it using |
Here's a benchmark suite that demonstrates the difference use atoi::{FromRadix10, FromRadix10Checked, FromRadix10Signed, FromRadix16, FromRadix16Checked};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::str;
use std::str::FromStr;
use std::fs::read_to_string;
pub fn i128_signed_four_digit_number(c: &mut Criterion) {
c.bench_function("signed i128 four digit number", |b| {
let lines: Vec<Vec<u8>> = read_to_string("/tmp/numbers")
.unwrap()
.lines()
.map(|l| l.as_bytes().into())
.collect();
b.iter(|| {
black_box(&lines)
.iter()
.map(|l| i128::from_radix_10_signed(l).0)
.collect::<Vec<_>>()
})
});
}
pub fn i128_through_utf8(c: &mut Criterion) {
c.bench_function("i128 via UTF-8", |b| {
let lines: Vec<Vec<u8>> = read_to_string("/tmp/numbers")
.unwrap()
.lines()
.map(|l| l.as_bytes().into())
.collect();
b.iter(|| {
black_box(&lines)
.iter()
.map(|l| {
let s = str::from_utf8(l).unwrap();
s.parse::<i128>().unwrap();
//i128::from_str(s).unwrap();
//atoi_radix10::parse_from_str(s).unwrap::<i128>();
})
.collect::<Vec<_>>()
})
});
}
criterion_group!(benches, i128_signed_four_digit_number, i128_through_utf8,);
criterion_main!(benches); std is 4x faster. Anything wrong about my benchmark? |
Not on the face of it. Wouldn't be able to reproduce without your numbers though. |
See first post, it's just a bunch of ints |
I was debugging this and wanted to write a reproducer. For some reason in my tests, std is always faster at parsing than this library. Anything wrong with my benchmark?
The text was updated successfully, but these errors were encountered: