frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Optimizing FizzBuzz in Rust

https://github.com/nrposner/fizzcrate
22•Bogdanp•8h ago

Comments

jasonjmcghee•6h ago
Reminds me of the famous thread on stack overflow. I'll link the rust one directly, but one cpp answer claims 283 GB/s - and others are in the ballpark of 50GB/s.

The rust one claims around 3GB/s

https://codegolf.stackexchange.com/a/217455

You can take this much further! I think throughput is a great way to measure it.

Things like pre-allocation, no branching, constants, simd, etc

hyperhello•6h ago
Maybe I’m missing something but can’t you unroll it very easily by 15 prints at a time? That would skip the modulo checks entirely, and you could actually cache everything but the last two or three digits.
Terretta•5h ago
> Maybe I’m missing something but can’t you unroll it very easily by 15...

Sure, 3 x 5 = 15. But, FTA:

But then, by coincidence, I watched an old Prime video and decided to put the question to him: how would you extend this to 7 = "Baz"?

He expanded the if-else chain: I asked him to find a way to do it without explosively increasing the number of necessary checks with each new term added. After some hints and more discussion...

Which is why I respectfully submit almost all examples of FizzBuzz including the article's first are "wrong" while the refactor is "right".

As for the optimizations, they don't focus on only 3 and 5, they include 7 throughout.

ainiriand•5h ago
In my opinion a more accurate measure when you go down to the micro seconds level is TSC directly from the CPU. I've built a benchmark tool for that https://github.com/sh4ka/hft-benchmarks

Also I think that CPU pining could help in this context but perhaps I need to check the code in my machine first.

vlovich123•1h ago
How does this compare with divan?
joshka•4h ago
If you're going to the effort of writing a procmacro, you may as well output a string from the macro instead of code.

If you're going idiomatic rust, then you might instead output a type that has a display impl rather than generating code that writes to stdout.

Etherlord87•3h ago
> At this point, I'm out of ideas. The most impactful move would probably be to switch to a faster terminal... but I'm already running Ghostty! I thought it was a pretty performant terminal to being with!

But what is the point? Why do you want to optimize the display? If you want to be able to fizz-buzz for millions of numbers, then you want to... Well realistically only compute them just before they are displayed.

Arnavion•1h ago
Because the display is the bottleneck.
Arnavion•1h ago
If OP is looking for ideas, there are two intermediate steps between the extremes of "write every line to stdout" and "build up a buffer of the whole output and then write it to stdout".

1. `stdout().lock()` and `writeln!()` to that. By default using `print*!()` will write to `stdout()` which takes a process-wide lock each time. (Funnily enough they use .lock() in the "build up a buffer of the whole output" section, just to do one .write_all() call, which is the one time they don't need to use .lock() because Stdout's impl of write_all() will only take the lock once anyway.)

2. Wrap the locked stdout in a `BufWriter` and `writeln!()` to that. It won't flush on every line, but it also won't buffer the entire output, so it's a middle point between speed and memory usage.

---

For the final proc macro approach, there is the option to unroll the loop in the generated code, and the option to generate a &'static str literal of the output.

AGI is an engineering problem, not a model training problem

https://www.vincirufus.com/posts/agi-is-engineering-problem/
72•vincirufus•3h ago•139 comments

The cost of interrupted work (2023)

https://blog.oberien.de/2023/11/05/23-minutes-15-seconds.html
116•_vaporwave_•5h ago•67 comments

Show HN: How to Build a Coding Agent (free workshop)

https://ghuntley.com/agent/
4•ghuntley•22m ago•0 comments

How can AI ID a cat?

https://www.quantamagazine.org/how-can-ai-id-a-cat-an-illustrated-guide-20250430/
108•sonabinu•3d ago•28 comments

Line scan camera image processing for train photography

https://daniel.lawrence.lu/blog/y2025m09d21/
225•dllu•11h ago•44 comments

A 2k-year-old sun hat worn by a Roman soldier in Egypt

https://www.smithsonianmag.com/smart-news/a-2000-year-old-sun-hat-worn-by-a-roman-soldier-in-egyp...
98•sensiquest•8h ago•13 comments

What makes Claude Code so damn good

https://minusx.ai/blog/decoding-claude-code/
205•samuelstros•8h ago•169 comments

Static sites with Python, uv, Caddy, and Docker

https://nkantar.com/blog/2025/08/static-python-uv-caddy-docker/
104•indigodaddy•1d ago•63 comments

Evaluating LLMs for my personal use case

https://darkcoding.net/software/personal-ai-evals-aug-2025/
9•goranmoomin•3h ago•0 comments

Physics of badminton's new killer spin serve

https://arstechnica.com/science/2025/08/physics-of-badmintons-new-killer-spin-serve/
35•amichail•3d ago•4 comments

Librebox: An open source, Roblox-compatible game engine

https://github.com/librebox-devs/librebox-demo
244•libreboxdevs•16h ago•66 comments

Taking a look at my old Palm IIIx – by Paul Lefebvre

https://www.goto10retro.com/p/taking-a-look-at-my-old-palm-iiix
9•rbanffy•3d ago•3 comments

Acronis True Image costs performance when not used

https://randomascii.wordpress.com/2025/05/26/acronis-true-image-costs-performance-when-not-used/
88•juanviera23•3d ago•18 comments

RFC 9839 and Bad Unicode

https://www.tbray.org/ongoing/When/202x/2025/08/14/RFC9839
220•Bogdanp•14h ago•116 comments

Texas Instruments’ new plants where Apple will make iPhone chips

https://www.cnbc.com/2025/08/22/apple-will-make-chips-at-texas-instruments-60-billion-us-project....
115•giuliomagnifico•1d ago•97 comments

Motion (YC W20) Is Hiring Principal Software Engineers

https://jobs.ashbyhq.com/motion/7355e80d-dab2-4ba1-89cc-a0197e08a83c?utm_source=hn
1•ethanyu94•6h ago

Why was Apache Kafka created?

https://bigdata.2minutestreaming.com/p/why-was-apache-kafka-created
97•enether•1d ago•92 comments

Debdelta

https://debdelta.debian.net/
15•Bogdanp•4h ago•2 comments

DeepCode: Open Agentic Coding

https://github.com/HKUDS/DeepCode
9•pykello•2h ago•2 comments

Romhack.ing's Internet Archive Mirror No Longer Available

https://romhack.ing/database/news/entry/DW8BKnRHSEqaGDwXTiKjMw
135•pharrington•7h ago•23 comments

Not so prompt: Prompt optimization as model selection (2024)

https://www.gojiberries.io/not-so-prompt-prompt-optimization-as-model-selection/
6•neehao•2h ago•0 comments

Hacker and physicist – a tale of "common sense"

https://www.supasaf.com/blog/general/hacker_physicist
19•supasaf•1d ago•5 comments

The Cornervery: A 90-Degree Stapler

https://www.core77.com/posts/138232/The-Cornervery-A-90-Degree-Stapler
30•surprisetalk•2d ago•6 comments

Libre – An anonymous social experiment without likes, followers, or ads

https://libreantisocial.com
88•rododecba•10h ago•120 comments

Writing Speed-of-Light Flash Attention for 5090 in CUDA C++

https://gau-nernst.github.io/fa-5090/
138•dsr12•15h ago•31 comments

Monoid-Augmented FIFOs, Deamortised

https://pvk.ca/Blog/2025/08/19/monoid-augmented-fifos/
31•todsacerdoti•4d ago•12 comments

Optimizing our way through Metroid

https://antithesis.com/blog/2025/metroid/
109•eatonphil•1d ago•18 comments

Exploring EXIF (2023)

https://hturan.com/writing/exploring-exif
57•jxmorris12•2d ago•8 comments

A simple way to generate random points on a sphere

https://www.johndcook.com/blog/2025/05/06/random-points-on-a-sphere/
60•piinbinary•4d ago•53 comments

450× Faster Joins with Index Condition Pushdown

https://readyset.io/blog/optimizing-straddled-joins-in-readyset-from-hash-joins-to-index-conditio...
106•marceloaltmann•4d ago•46 comments