←back to thread

Zlib-rs is faster than C

(trifectatech.org)
341 points dochtman | 1 comments | | HN request time: 0.233s | source
Show context
kahlonel ◴[] No.43381785[source]
You mean the implementation is faster than the one in C. Because nothing is “faster than C”.
replies(11): >>43381811 #>>43381892 #>>43382209 #>>43382286 #>>43382342 #>>43382418 #>>43382745 #>>43383389 #>>43383690 #>>43384451 #>>43392826 #
dijit ◴[] No.43382286[source]
The kind of code you can write in rust can indeed be faster than C, but someone will wax poetic about how anything is possible in C and they would be valid.

The major reason that rust can be faster than C though, is because due to the way the compiler is constructed, you can lean on threading idiomatically. The same can be true for Go, coroutines vs no coroutines in some cases is going to be faster for the use case.

You can write these things to be the same speed or even faster in C, but you won’t, because it’s hard and you will introduce more bugs per KLOC in C with concurrency vs Go or Rust.

replies(1): >>43383454 #
1. gf000 ◴[] No.43383454[source]
> but someone will wax poetic about how anything is possible in C and they would be valid.

Not at all would that be valid.

C has a semantic model which was close to how early CPUs worked, but a lot has changed since. It's more like CPUs deliberately expose an API so that C programmers could feel at home, but stuff like SIMD and the like is non-existent in C besides as compiler extensions. But even just calling conventions, the stack, etc are all stuff you have no real control over in the C language, and a more optimal version of your code might want to do so. Sure, the compiler might be sufficiently smart, but then it might as well convert my Python script to that ultra-efficient machine code, right?

So no, you simply can't write everything in C, something like simd-json is just not possible. Can you put inline assembly into C? Yeah, but I can also call inline assembly from Scratch and JS, that's not C at all.

Also, Go is not even playing in the same ballpark as C/C++/Rust.