Most active commenters

    ←back to thread

    Zlib-rs is faster than C

    (trifectatech.org)
    341 points dochtman | 20 comments | | HN request time: 0.536s | source | bottom
    1. 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 #
    2. arlort ◴[] No.43381811[source]
    Tachyons?
    replies(1): >>43382001 #
    3. mkoubaa ◴[] No.43381892[source]
    C after an optimizing compiler has chewed through it is faster than C
    4. einpoklum ◴[] No.43382001[source]
    Maybe if you reverse the beam polarity and route them through the main deflector array.
    replies(1): >>43382326 #
    5. Jaxan ◴[] No.43382209[source]
    Of course many things can be faster than C, because C is very far from modern hardware. If you compile with optimisation flags, the generated machine code looks nothing like what you programmed in C.
    6. 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 #
    7. layer8 ◴[] No.43382326{3}[source]
    But that requires rerouting auxiliary power from life support to the shield generators. In Rust you would need to use unsafe for that.
    8. pornel ◴[] No.43382342[source]
    If you don't count manual SIMD intrinsics or inline assembly as C, then Rust and FORTRAN can be faster than C. This is mainly thanks to having pointer aliasing guarantees that C doesn't have. They can get autovectorization optimizations where C's semantics get in the way.
    9. nindalf ◴[] No.43382418[source]
    Why can’t something be faster than C? If a language is able to convey more information to a backend like LLVM, the backend could use that to produce more optimised code than what it could do for C.

    For example, if the language is able to say, for any two pointers, the two pointers will not overlap - that would enable the backend to optimise further. In C this requires an explicit restrict keyword. In Rust, it’s the default.

    By the way this isn’t theoretical. Image decoders written in Rust are faster than ones written in C, probably because the backend is able to autovectorise better. (https://www.reddit.com/r/rust/comments/1ha7uyi/memorysafe_pn...).

    grep (C) is about 5-10x slower than ripgrep (Rust). That’s why ripgrep is used to execute all searches in VS Code and not grep.

    Or a different tack. If you wrote a program that needed to sort data, the Rust version would probably be faster thanks to the standard library sort being the fastest, across languages (https://github.com/rust-lang/rust/pull/124032). Again, faster than C.

    Happy to give more examples if you’re interested.

    There’s nothing special about C that entitles it to the crown of “nothing faster”. This would have made sense in 2005, not 2025.

    replies(1): >>43382557 #
    10. burntsushi ◴[] No.43382557[source]
    Narrow correction on two points:

    First, I would say that "ripgrep is generally faster than GNU grep" is a true statement. But sometimes GNU grep is faster than ripgrep and in many cases, performance is comparable or only a "little" slower than ripgrep.

    Secondly, VS Code using ripgrep because of its speed is only one piece of the picture. Licensing was also a major consideration. There is an issue about this where they originally considered ripgrep (and ag if I recall correctly), but I'm on mobile so I don't have the link handy.

    11. kllrnohj ◴[] No.43382745[source]
    It is quite easy for C++ and Rust to both be faster than C in things larger than toy projects. C is hardly a panacea of efficiency, and the language makes useful things very hard to do efficiently.

    You can contort C to trick it into being fast[1], but it quickly becomes an unmaintainable nightmare so almost nobody does.

    1: eg, correct use of restrict, manually creating move semantics, manually creating small string optimizations, etc...

    12. gf000 ◴[] No.43383389[source]
    Wtf, since when?

    Besides the famous "C is not a low-level language" blog post.. I don't even get what you are thinking. C is not even the performance queen for large programs (the de facto standard today is C++ for good reasons), let alone for tiny ultra hot loops like codecs and stuff, which are all hand-written assembly.

    It's not even hard to beat C with something like Rust or C++, because you can properly do high level optimizations as the language is expressive enough for that.

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

    14. xboxnolifes ◴[] No.43383690[source]
    In the chance this is a speed of light joke, I'll add pedantically that C isn't the speed of light. Mathematics/Physics symbols are case sensitive.
    15. cozzyd ◴[] No.43384451[source]
    Nothing is faster than C in a vacuum, but depending on the context (medium?) that can happen.

    In other words, someone should name a language Cerenkov

    replies(1): >>43385619 #
    16. oneshtein ◴[] No.43385619[source]
    Gravitation is slightly faster than c in vacuum.
    replies(1): >>43385713 #
    17. hyperbrainer ◴[] No.43385713{3}[source]
    In GR, the speed of gravitational waves is _exactly equal_ to c.
    replies(1): >>43389558 #
    18. oneshtein ◴[] No.43389558{4}[source]
    In reality, speed of light is slightly lower than speed of gravitation, because gravitation slows down speed of light.
    replies(1): >>43390036 #
    19. hyperbrainer ◴[] No.43390036{5}[source]
    We were presumably talking about an ideal massless space [Minkowski] in which the speed of light in a vaccuum is considered -- that is what c is defined as.
    20. knorker ◴[] No.43392826[source]
    Fortran has been faster than C, because C has aliasing, preventing optimizations. At least for decades this was why for some applications Fortran was just faster.

    It's not just "a sufficiently smart compiler", without completely unrealistic (as in "halting problem" unrealistic, in the general case) "smartness".

    So no, C is inherently slower than some other languages.