27 ms·
The first example, reading lines in a file, is really slow. Depending on the input, it could be 4x-10x slower. In Go, the equivalent `ReadLine` is implemented o
by latch 3y ago
The first example, reading lines in a file, is really slow. Depending on the input, it could be 4x-10x slower. In Go, the equivalent `ReadLine` is implemented on `bufio.Reader`. Thus the implementation can take advantage of the buffering.
In Zig, while this example does use a BufferedReader, the `streamUntilDelimiter` is implemented on the more generic `std.io.Reader` and thus cannot take full advantage of the buffering. It checks 1 byte at a time, and cannot leverage the SIMD-optimized `std.mem.indexOfScalar`.
Of course, you're free to create your own `readLines` that works against a BufferedReader. I do hope we'll see a whole version dedicated to review/polishing of the standard library. And maybe more work on composition, abstraction and interfaces.
The issue is described here: https://github.com/ziglang/zig/issues/17985 https://github.com/ziglang/zig/issues/17985
- anonymoushn 3y agoThanks for highlighting this. Internally we're mostly avoiding the parts of the std Reader interface that impose significant runtime costs if you use them, but it would be swell to upgrade the stdlib implementations to do something like golang interface upgrades for buffered readers.