• Luci@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    1 month ago

    Rust running slower than C?

    Never would have guessed……

    Edit: LMAO

        • trevor (he/they)@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          0
          ·
          1 month ago

          I have no idea how. I write better Rust than I do C 🤷‍♂️

          Rust and C are basically identical in terms of performance (more or less). Idk where the myth that Rust is somehow less performant than C came from.

          • Possibly linux@lemmy.zip
            link
            fedilink
            English
            arrow-up
            0
            ·
            1 month ago

            It depends on what you are counting as “performance”

            Good C code is way better than mediocre Rust code. C also has much smaller binaries.

            • BatmanAoD@programming.dev
              link
              fedilink
              arrow-up
              0
              ·
              1 month ago

              If your goal is small binaries, it’s possible to get them with Rust, too: https://github.com/johnthagen/min-sized-rust

              There are a variety of reasons why Rust binaries tend to be bigger unless you follow some of those guidelines, but the biggest one (and actually not something those guidelines recommend changing!) is that C is generally dynamically linked against a system version of the C standard library, whereas Rust binaries are statically linked by default, meaning that the binary is actually self-contained.

              • Samueru_sama@programming.dev
                link
                fedilink
                English
                arrow-up
                0
                ·
                1 month ago

                whereas Rust binaries are statically linked by default, meaning that the binary is actually self-contained.

                rust still produces larger binaries even if you compare it to static C binaries.

                Take for example busybox, you can compile all of it as a single 1.2 MiB static binary that provides 395 utilities including wget.

                Meanwhile the uutils static musl binary is 12 MiB and only provides 115 utilities.

                • BatmanAoD@programming.dev
                  link
                  fedilink
                  arrow-up
                  0
                  ·
                  1 month ago

                  That’s not a fair comparison at all. Busybox is specifically optimized for size, and to accomplish that, leaves out a large number of GNU compatibility features; uutils is designed to mimic GNU as closely as possible, and I’m assuming that the binary you’re looking at is not the “small-release” build. Just to see what that looks like, I’ve built it that way now and that puts it under 7 MiB; still much larger than busybox, but it shows how much the optimization choices matter.