# codegen: writer\(\)\.writeByteNTimes \-\> appendNTimes · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d962ad5ea0290ea4b713f5546eb12032351cb7b9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d962ad5ea0290ea4b713f5546eb12032351cb7b9

Requested commit: d962ad5ea0290ea4b713f5546eb12032351cb7b9

Commit: d962ad5ea0290ea4b713f5546eb12032351cb7b9

Tree: cfec9eed2540ce60061257ad53dfe64126b27674

Author: r00ster91

Committer: Andrew Kelley

## Message

```
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.

```

## Parents

- [619140c0d2abd22da668747820f0ee80b497eb24](https://git.cafe/gitcafe/zig/commit/619140c0d2abd22da668747820f0ee80b497eb24?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d962ad5ea0290ea4b713f5546eb12032351cb7b9?format=markdown)
