Skip to content
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

Question. Speed on large inputs. #82

Open
scheglov opened this issue Oct 5, 2023 · 1 comment
Open

Question. Speed on large inputs. #82

scheglov opened this issue Oct 5, 2023 · 1 comment

Comments

@scheglov
Copy link

scheglov commented Oct 5, 2023

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
Copy link
Author

scheglov commented Oct 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant