Henry John Kupty 163ebe044b
std.mem.countScalar: rework to benefit from simd (#25477)
`findScalarPos` might do repetitive work, even if using simd. For
example, when searching the string `/abcde/fghijk/lm` for the character
`/`, a 16-byte wide search would yield `1000001000000100` but would only
count the first `1` and re-search the remaining of the string.

When testing locally, the difference was quite significative:
```
count scalar
  5737 iterations       522.83us per iterations
  0 bytes per iteration
  worst: 2370us median: 512us   stddev: 107.64us

count v2
  38333 iterations      78.03us per iterations
  0 bytes per iteration
  worst: 713us  median: 76us    stddev: 10.62us

count scalar v2
  99565 iterations      29.80us per iterations
  0 bytes per iteration
  worst: 41us   median: 29us    stddev: 1.04us
```

Note that `count v2` is a simpler string search, similar to the
remaining version of the simd approach:
```
pub fn countV2(comptime T: type, haystack: []const T, needle: T) usize {
    const n = haystack.len;
    if (n < 1) return 0;
    var count: usize = 0;
    for (haystack[0..n]) |item| {
        count += @intFromBool(item == needle);
    }

    return count;
}
```

Which implies the compiler yields some optimized code for a simpler loop
that is more performant than the `findScalarPos`-based approach, hence
the usage of iterative approach for the remaining of the haystack.

Co-authored-by: StAlKeR7779 <stalkek7779@yandex.ru>
2025-10-07 09:32:13 -07:00
..
2025-09-30 13:44:51 +01:00
2025-10-04 02:31:02 +00:00
2025-07-07 22:43:51 -07:00
2025-10-03 16:29:09 -07:00
2025-09-18 22:39:33 -07:00
2025-09-30 13:44:54 +01:00
2025-10-06 06:54:52 +02:00
2025-09-03 21:46:01 -07:00
2025-09-18 22:39:33 -07:00
2025-08-29 17:14:26 -07:00
2025-09-30 13:44:54 +01:00
2025-09-18 22:39:33 -07:00
2025-08-31 12:49:18 -07:00
2025-08-28 18:30:57 -07:00
2025-09-30 13:44:51 +01:00
2025-09-20 14:34:18 -07:00
2024-08-22 08:44:08 +02:00
2025-09-30 13:44:53 +01:00
2025-09-11 00:18:37 -07:00
2025-07-31 22:10:11 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-09-18 22:39:33 -07:00
2025-09-30 13:44:51 +01:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-09-30 13:44:55 +01:00
2025-07-22 09:41:44 -07:00
2025-10-06 01:28:56 +02:00
2025-09-30 13:44:51 +01:00
2025-08-28 18:30:57 -07:00
2025-08-31 12:49:18 -07:00
2025-08-31 12:49:18 -07:00
2025-07-16 10:27:39 -07:00
2025-09-24 20:01:18 -07:00
2025-08-29 17:14:26 -07:00