Announcement

Collapse
No announcement yet.

uutils 0.0.16 Released As Rust-Based GNU Coreutils Replacement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #81
    Originally posted by Volta View Post

    That's a nice feature to have. However, shouldn't they be more or less equal now? C being two times faster is noticeable difference. The code is simple:

    rustc -C opt-level=3 main.rs

    real 0m39,146s
    user 0m39,057s
    sys 0m0,003s​

    ------------------------

    gcc -O3 main.c

    real 0m23,589s
    user 0m23,532s
    sys 0m0,003s

    n == 50
    Needing to drop the recursion perhaps isn't ideal, but try out the code below, in both C and rust. I suspect they should be very close, and both quite a bit faster than the recursive functions which would indicate it's probably a more practical test in terms of what would actually be running in real apps which care about performance.

    Code:
    fn fibonacci_iterative(n: i64) -> i64 {
        let mut first_number:i64;
        let mut second_number:i64 = 0;
        let mut current_number:i64 = if n == 0 { 0 } else { 1 };
     
        let mut i:i64 = 1;
        while i < n {
            first_number = second_number;
            second_number = current_number;
            current_number = first_number + second_number;
            i = i + 1;
        }
        return current_number;
    }​
        
    fn main() {
        println!("{}", fibonacci_iterative(50));
    }​
    Last edited by smitty3268; 17 October 2022, 10:54 PM.

    Comment


    • #82
      Originally posted by Volta View Post
      From what I've notice Rust is two times slower than C (e.g. Fibonacci) and its smallest binaries (10 LoC) are about 15 times bigger.
      Read these, for me it was a interesting:
      https://lifthrasiir.github.io/rustlo...ble-large.html


      Summary (with references to the first link):
      - 50% are debug symbols (you can strip them)
      - the Rust compiler/linker links statically vs. C dynamically (you can link dynamically)
      - some standard libs (e.g. for memory allocation) are included, even when your program does not need them (you can have them removed)
      - the resulting Rust program is as small as the C program
      - the standard Rust program is fully debugable and includes some libs to achieve this; this can all be stripped

      I wonder how this is for larger programs, "Hello, World!" is very small so the effects are surely different from normal programs
      Last edited by reba; 18 October 2022, 03:05 AM.

      Comment


      • #83
        Originally posted by reba View Post

        Read these, for me it was a interesting:
        https://lifthrasiir.github.io/rustlo...ble-large.html


        Summary (with references to the first link):
        - 50% are debug symbols (you can strip them)
        - the Rust compiler/linker links statically vs. C dynamically (you can link dynamically)
        - some standard libs (e.g. for memory allocation) are included, even when your program does not need them (you can have them removed)
        - the resulting Rust program is as small as the C program
        - the standard Rust program is fully debugable and includes some libs to achieve this; this can all be stripped
        You neglected to mention that part where they used CFLAGS='-Os -flto -Wl,--gc-sections -static -s'​ with the C example and -C link-args=-static​ with the Rust example to compare apples to apples for static linkage and wound up with a C binary significantly bigger than the Rust binary.
        Last edited by ssokolow; 18 October 2022, 08:21 AM.

        Comment


        • #84
          Originally posted by ssokolow View Post

          You neglected to mention that part where they used CFLAGS='-Os -flto -Wl,--gc-sections -static -s'​ with the C example and -C link-args=-static​ with the Rust example to compare apples to apples for static linkage and wound up with a C binary significantly bigger than the Rust binary.
          True.

          My point was not to prove for compiled programs
          "C is much worse than Rust" on Rust-terms (static, debug, etc.)
          but
          "Rust is not worse than C" on C-terms (stripped, using external libs, etc.)
          Last edited by reba; 18 October 2022, 10:02 AM.

          Comment


          • #85
            Originally posted by reba View Post

            True.

            My point was not to prove for compiled programs
            "C is much worse than Rust" on Rust-terms (static, debug, etc.)
            but
            "Rust is not worse than C" on C-terms (stripped, using external libs, etc.)
            Fair. I still think it's important context though.

            Comment

            Working...
            X