Better HN
topnewbestaskshowjobs
Log inSign up

nheer

1 karma · joined Nov 22, 2025 (1y ago) · 7 submissions

Submissions

comment 11mo ago · link · parent

Thanks for the links - the benchmarks game is a great resource and has been around for a long time.

That said, I'm not sure what "do better" means here. This is an open source project I maintain in my spare time. If you see room for improvement, PRs are always welcome. That's how open source works - if something is useful to you and you want it improved, contribute.

The project exists because some people find it useful. If it's not for you, that's fine too.

comment 11mo ago · link · parent

Author here. There are actually 3 Swift versions in the benchmark:

  - Swift (standard): 893ms
  - Swift (relaxed): 903ms (uses fast-math equivalent)
  - Swift (SIMD): 509ms (explicit SIMD4)
The standard version uses x *= -1.0 which creates a loop-carried dependency that blocks auto-vectorization - same issue as Crystal, Odin, Ada. The SIMD version uses the branchless i & 0x1 trick and is ~1.75x faster.

Fair point that someone versed in Swift would probably use the better pattern in the standard version too. PRs welcome to improve it! The goal was idiomatic-ish code, but I'm not an expert in all 40+ languages.

comment 11mo ago · link · parent

Author here. I just tested this with Zig by timing the segments inside the program:

  1 billion iterations:
  - Startup + file read: 0.01ms
  - Computation: ~200ms
  - Overhead: 0.01%
Even at 1 million iterations (0.24ms total), startup is only 4% overhead. At 1 billion it's essentially zero.

The benchmark is definitely measuring the hot loop, not startup time.

comment 11mo ago · link · parent

Author here! Thanks for the detailed breakdown. Let me address a few points:

- C++ SIMD being slower: The standard C++ uses i & 0x1 which lets the compiler auto-vectorize. With -O3 -ffast-math -march=native, gcc/clang do this really well. The explicit AVX2 version has overhead from manual vector setup and horizontal sum at the end. Modern compilers often beat hand-written SIMD for simple loops like this.

- Zig fast-math: Correct. Line 5 has @setFloatMode(.optimized) with a comment saying "like C -ffast-math".

- Julia: Also correct. Uses @fastmath @simd for - both annotations together.

- Crystal/Odin/Ada being slow: All three use x = -x which creates a loop-carried dependency that blocks auto-vectorization. The fast implementations use the branchless i & 0x1 trick instead.

- C# SIMD: Uses Vector512 doing 8 doubles per iteration. That explains the ~4x speedup.

- Nim vs C: Both compile via gcc with similar flags. Probably just measurement variance.

- Fortran: Interestingly does NOT use -ffast-math. Uses manual loop unrolling instead (processes 4 terms per iteration).

- Go: You're right that it's the fastest with its own compiler. No LLVM/GCC backend, just Go's own SSA-based compiler.

For suggestions - DMD, LFortran, and Scala Native would be great additions. PRs welcome!

comment 11mo ago · link · parent

Author here — yep, you understood the repository correctly.

My Python version is a good example of the structure: read rounds.txt, run the loop, print the result, exit. I’m timing the whole program with hyperfine.

I agree that for a “pure compute” microbenchmark you could remove file I/O and console output. I kept them mainly because:

- It gives every language the same simple interface (same input, same output) and acts as a basic correctness/sanity check.

- The benchmark runs 1 billion iterations. The file read and a single print happen once per run, so that overhead is tiny compared to the loop, and the results stay comparable in practice.

That said, I’m not against a compute-only / quiet mode. Since hyperfine already handles timing externally, the real work is implementing and maintaining a consistent --quiet / --no-io variant across 50+ languages.

If someone wants to contribute that (even starting with a subset), I’m happy to review PRs.

comment 11mo ago · link · parent

Thank you for your comment.

> > a silly little experiment

> This I don't like.

What do you mean with that?

To explain what I meant. I knew that that in the end this was a microbenchmark. It can certainly give you some clue about a language, but it doesn't tell you the whole picture. In the end it tells you how good a language is (or can be) at loops and floating point math. That's what I meant. I hope that makes it clearer.

comment 11mo ago · link · parent

Hi everyone, author here!

I’m genuinely blown away by all the interest in what started as a silly little experiment. The project grew way beyond its original scope. My initial curiosity was simply: how could you set up a pipeline to do automatic speed comparisons? I was less interested in the results as a definitive measure and more in the infrastructure challenge itself.

But then the interest kept growing. I tried to modernize things, but one thing became quite notable: the difference between a language that gets actively optimized by its community (like Julia) versus one that just sits there unoptimized is striking.

Honestly, I got overwhelmed. Managing all those implementations, keeping versions up to date, reviewing contributions—it was a lot. I basically tapped out for about a year.

Now I’m back, and with AI assistance, maintaining this has become much more realistic—updating versions, helping optimize implementations, etc. That said, I’m always happy to accept contributions from folks who know their languages better than I do.

Thank you all for your interest and the thoughtful discussion!