Skip to content

Commit

Permalink
rust: use more idiomatic ascii comparisons
Browse files Browse the repository at this point in the history
Surprisingly, this tiny change yields a 15% speed up.
  • Loading branch information
rmg committed Mar 21, 2023
1 parent fc4391d commit 0ea6b02
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) | 0m2.169s | 0m1.943s | 0m0.219s |
| simple (Rust) | 0m1.623s | 0m1.415s | 0m0.204s |
| 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 @@ -26,7 +26,7 @@ fn scan_slice(inb: &[u8]) -> usize {
let mut count = 0;
let len = inb.len();
for (i, &b) in inb.into_iter().enumerate() {
if b >= b'0' && b <= b'9' || b >= b'a' && b <= b'f' {
if b.is_ascii_digit() || (b'a'..=b'f').contains(&b) {
count += 1;
continue
}
Expand Down

0 comments on commit 0ea6b02

Please sign in to comment.