aboutsummaryrefslogtreecommitdiff
path: root/benches/from_utf8_lossy.rs
blob: 95d9edf3924ab46fdd6937cc80acb79d290a2422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![feature(test)]

extern crate test;
extern crate utf8;

#[path = "../tests/shared/data.rs"]
mod data;

#[path = "../tests/shared/string_from_utf8_lossy.rs"]
mod string_from_utf8_lossy;

#[bench]
fn bench_our_string_from_utf8_lossy(bencher: &mut test::Bencher) {
    bencher.bytes = data::DECODED_LOSSY.iter().map(|&(input, _expected)| input.len() as u64).sum();
    bencher.iter(|| {
        for &(input, _expected) in data::DECODED_LOSSY {
            test::black_box(string_from_utf8_lossy::string_from_utf8_lossy(input));
        }
    })
}

#[bench]
fn bench_std_string_from_utf8_lossy(bencher: &mut test::Bencher) {
    bencher.bytes = data::DECODED_LOSSY.iter().map(|&(input, _expected)| input.len() as u64).sum();
    bencher.iter(|| {
        for &(input, _expected) in data::DECODED_LOSSY {
            test::black_box(String::from_utf8_lossy(input));
        }
    })
}