Skip to content

Commit

Permalink
rust: reduce read buffer size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmg committed Mar 21, 2023
1 parent 0ea6b02 commit 2124332
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** |

Expand Down
2 changes: 1 addition & 1 deletion main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2124332

Please sign in to comment.