From 21243323cee05fd5a946f0738de760113c265850 Mon Sep 17 00:00:00 2001 From: Ryan Graham Date: Tue, 21 Mar 2023 09:53:54 -0700 Subject: [PATCH] rust: reduce read buffer size Reduce the size of the read buffer from 64MB to 256K which is much friendlier to the CPU cache. This is the same size as used by the optimized C version and it turns out to yield a small performance boost here as well. In fact, it provides enough of a speed up that the naive implementation in Rust is now consistently faster than ripgrep, which is a little surprising. --- README.md | 2 +- main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5fab4c..081b8da 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ implementations compare to each other. | grep | 0m18.034s | 0m15.713s | 0m2.257s | | ripgrep | 0m1.709s | 0m1.541s | 0m0.147s | | simple (Go) | 0m1.889s | 0m1.679s | 0m0.211s | -| simple (Rust) | 0m1.623s | 0m1.415s | 0m0.204s | +| simple (Rust) | 0m1.461s | 0m1.325s | 0m0.131s | | simple (Node) | 0m6.458s | 0m6.043s | 0m0.627s | | custom (C) | **0m0.222s** | **0m0.079s** | **0m0.141s** | diff --git a/main.rs b/main.rs index f9540b6..3acb970 100644 --- a/main.rs +++ b/main.rs @@ -43,7 +43,7 @@ fn scan_slice(inb: &[u8]) -> usize { } fn sscan(mut input: impl Read) { - let mut backbuf = vec![0u8; 64*1024*1024]; + let mut backbuf = vec![0u8; 64*4096]; let bbuf = backbuf.as_mut_slice(); // let mut bbuf = [0u8; 2*1024*1024]; let mut off = 0;