{"id":18872966,"url":"https://github.com/18alantom/fizzbuzz","last_synced_at":"2026-02-16T02:30:16.702Z","repository":{"id":199094794,"uuid":"702132946","full_name":"18alantom/fizzbuzz","owner":"18alantom","description":"Fizz buzz in Zig (w.i.p).","archived":false,"fork":false,"pushed_at":"2023-10-28T10:48:39.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-31T00:29:18.769Z","etag":null,"topics":["zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/18alantom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-08T15:37:54.000Z","updated_at":"2023-11-01T17:10:52.000Z","dependencies_parsed_at":"2023-10-28T11:26:10.769Z","dependency_job_id":null,"html_url":"https://github.com/18alantom/fizzbuzz","commit_stats":null,"previous_names":["18alantom/fizzbuzz"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/18alantom%2Ffizzbuzz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/18alantom%2Ffizzbuzz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/18alantom%2Ffizzbuzz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/18alantom%2Ffizzbuzz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/18alantom","download_url":"https://codeload.github.com/18alantom/fizzbuzz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239824981,"owners_count":19703199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["zig"],"created_at":"2024-11-08T05:33:15.313Z","updated_at":"2026-02-16T02:30:16.626Z","avatar_url":"https://github.com/18alantom.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast Fizz Buzz using Zig\n\n`fizzbuzz.zig` generates [fizz buzz](https://en.wikipedia.org/wiki/Fizz_buzz)\noutput. This is piped through [pv](http://www.ivarch.com/programs/pv.shtml) to\nmeasure data throughput. The output is finally piped to `/dev/null`.\n\nThis code aims to maximize fizz buzz data throughput.\n\n## Exec-env\n\n```\nOS: macOS 13.5.2 22G91 arm64\nShell: zsh 5.9\nTerminal: iTerm2\nCPU: Apple M1 Pro\nMemory: 32768MiB\n\n```\n\n**Baseline**: `/dev/zero pv \u003e /dev/null` is 34.6GiB/s\n\n## Runs\n\n_Note: reasoning is mostly a guess._\n\n1.  **naive implementation**: `9.89MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/173578984cae2e13f3f3f3a5dd4369926d96b84a/fizzbuzz.zig)\n    - `0:01:10 for 700 MiB (n: 100_000_000) at 9.89MiB/s`\n2.  **use `std.c.printf`**: `127MiB/s`\n    - `0:00:58 for 7.33 GiB (n: 1_000_000_000) at 127MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/62fbe6c14ece93f747061e9afb6705a073f78c60/fizzbuzz.zig)\n    - C std lib [`printf`](https://man7.org/linux/man-pages/man3/fprintf.3.html) directly writes to stdout, [`writer.write`](https://github.com/ziglang/zig/blob/d68f39b5412e0aeb59d71c9f676221212261dc8c/lib/std/fs/file.zig#L1157) consists of several comparisons, and might return errors which pulls in `builtin.returnError`.\n3.  **use buffered writer, faster custom int formatter**: `192MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/845f435d12495149a0bf72940dca5d61e30678a7/fizzbuzz.zig)\n    - `0:00:38 for 7.33 GiB (n: 1_000_000_000) at 192MiB/s`\n    - Consists of 2 improvements:\n      1. Used a buffered writer which writes output to a 4MB buffer before flushing it to\n         stdout using `c.printf`. The buffer size was based off of [this experiment](https://gist.github.com/18alantom/fac21902a1e7b295cac16f3772f42df3#file-fast_zeros-zig) which is probably\n         still not optimized for whatever lies between printf invocation and stdout receiving\n         the bytes. But it's still better than calling printf for every line of output.\n      2. Used a custom int formatter for digit to string conversion. Using\n         `fmt.bufPrint` makes it slower than the previous run probably cause\n         error handling and call stack.\n4.  **use `c.write`**: `205MiB/s`\n    - `00:00:36 for 7.33 GiB (n: 1_000_000_000) at 205MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/06a04aaa83a4971885ea0529c9c083ff26a3b975/fizzbuzz.zig)\n    - Formatting is not required so `c.write` to `STDOUT` can be used directly.\n      Speed up probably cause no checks for format strings.\n5.  **use SIMD `@Vector`**: `354MiB/s`\n    - `00:00:21 for 7.33GiB (n: 1_000_000_000) at 354MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/bdc1040a03691a85ddcea4798b7cdd880854fdef/fizzbuzz.zig)\n    - Since Fizz Buzz output shape repeats every 15 iterations, vectorization can be used\n      to calculate the next set of 8 numbers in a single iteration. In using vectorization,\n      the write function had to be regressed to using `c.printf` since given\n      formatting, for now that would be the fastest.\n6.  **use 1MB output buffer**: `368MiB/s`\n    - `00:00:20 for 7.33GiB (n: 1_000_000_000) at 368MiB/s` [src](https://github.com/18alantom/fizzbuzz/blob/cba7ea4123e123a6324302c4ad5a0da62107a5e1/fizzbuzz.zig)\n    - Use `setvbuf` to set stdout to use full buffering (`IOFBF`) with a 1MB buffer. Without\n      this, writes to stdout are flushed on new lines by default and full buffering should\n      lead to fewer writes.\n      \n7.  **??**: `??MiB/s`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F18alantom%2Ffizzbuzz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F18alantom%2Ffizzbuzz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F18alantom%2Ffizzbuzz/lists"}