simdutf8 icon indicating copy to clipboard operation
simdutf8 copied to clipboard

Question. Speed on large inputs.

Open scheglov opened this issue 2 years ago • 1 comments

Why do I get only about 12 GB/s with this manual benchmark?

use std::time::Instant;

use simdutf8::basic::from_utf8;

fn main() {
    let mut vec: Vec<u8> = Vec::new();

    for i in 0..1024 * 1024 * 10 {
        vec.push((i % 10) as u8 + b'0');
    }

    // println!("{:?}", vec);

    println!("{}", from_utf8(b"I \xE2\x9D\xA4\xEF\xB8\x8F UTF-8!").unwrap());

    let start = Instant::now();

    let decoded = from_utf8(vec.as_slice()).unwrap();
    // let decoded = std::str::from_utf8(vec.as_slice()).unwrap();
    println!("length: {}", decoded.len());

    let mut elapsed = Instant::now().duration_since(start);
    println!("Elapsed time: {:?}", elapsed);
    let giga = 1024 * 1024 * 1024;
    println!("Speed: {:?} GB/s", 1000000.0 / (elapsed.as_micros() as f64) * (vec.len() as f64) / (giga as f64));
}

When I run the benchmark (slightly patched), I get about 80 GB/s.

1-latin/1048576         time:   [12.134 µs 12.144 µs 12.155 µs]
                        thrpt:  [80.339 GiB/s 80.416 GiB/s 80.481 GiB/s]

scheglov avatar Oct 05 '23 14:10 scheglov

cargo 1.65.0 (4bc8f24d3 2022-10-20) and Apple M1 Pro

scheglov avatar Oct 05 '23 14:10 scheglov