diff options
| author | r00ster91 <r00ster91@proton.me> | 2023-07-22 00:16:08 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-07-21 21:32:18 -0700 |
| commit | d962ad5ea0290ea4b713f5546eb12032351cb7b9 (patch) | |
| tree | cfec9eed2540ce60061257ad53dfe64126b27674 /lib/std/json/stringify_test.zig | |
| parent | 619140c0d2abd22da668747820f0ee80b497eb24 (diff) | |
| download | zig-d962ad5ea0290ea4b713f5546eb12032351cb7b9.tar.gz zig-d962ad5ea0290ea4b713f5546eb12032351cb7b9.zip | |
codegen: writer().writeByteNTimes -> appendNTimes
Both ways do the same thing but I think the compiler might have an
easier time optimizing `appendNTimes` because it does less
things/the path is shorter.
I have not done any benchmarking at runtime but have compared the
instruction count of both ways a little here: https://zig.godbolt.org/z/vr193W9oj
`b` (`appendNTimes`) is ~103 instructions while `a`
(`writer().writeByteNTimes`) is ~117 instructions.
And looking at the implementation of `writeByteNTimes`, it only seems to
buffer up 256 bytes before doing another `writeAll` which for
`std.ArrayList` probably means another allocation, whereas when directly
using `appendNTimes`, the entire exact additional capacity required is known from the start.
Either way, this would be more consistent anyway.
Diffstat (limited to 'lib/std/json/stringify_test.zig')
0 files changed, 0 insertions, 0 deletions
