1. 3

    For fun, I tried it with another language that uses LLVM: Zig 0.4.0.

    const std = @import("std");
    const hello_world = "Hello, world!\n";
    
    pub fn main() !void {
        const stdout_file = try std.io.getStdOut();
        // 1200000 lines of:
        try stdout_file.write(hello_world);
    }
    
    ❱ zig build-exe stress.zig
    00:03:10 elapsed
    

    I’m still waiting on the release build; it’s making my laptop sweaty.

    1. 2

      I really just feel like this should be extrapolated as a stress test for every language, just for fun.

      1. 1
        #include <stdio.h>
        int main() {
         // x1200000
         printf("hello, world\n");
         ...
         return 0;
        }
        

        Time taken on a 2013 MacBook Pro:

        bash-3.2$ time clang gen.c
        
        real	0m25.644s
        user	0m21.782s
        sys	0m1.790s
        

        (the executable is apparently 23m)

        1. 2

          (the executable is apparently 23m)

          It’s time to introduce un-unroll optimizations!

          1. 4

            Loop rolling!

            1. 1
              time clang -Oz gen.c
                      146.30 real       108.65 user         7.60 sys
              
              ls -al -h a.out
              -rwxr-xr-x  1 calmbit  staff   9.2M Oct  3 18:13 a.out
              

              Hmm! Interesting results. An obvious reduction, but not as big of one as I would have thought.

              The disassembly is a disaster, and looks something like:

              Disassembly of section __TEXT,__text:
              __text:
              10000136c:      55      pushq   %rbp
              10000136d:      48 89 e5        movq    %rsp, %rbp
              100001370:      53      pushq   %rbx
              100001371:      50      pushq   %rax
              100001372:      48 8d 1d 31 7c 92 00    leaq    9600049(%rip), %rbx
              100001379:      48 89 df        movq    %rbx, %rdi
              10000137c:      e8 09 7c 92 00  callq   9600009 <dyld_stub_binder+0x100928f8a>
              100001381:      48 89 df        movq    %rbx, %rdi
              100001384:      e8 01 7c 92 00  callq   9600001 <dyld_stub_binder+0x100928f8a>
              100001389:      48 89 df        movq    %rbx, %rdi
              10000138c:      e8 f9 7b 92 00  callq   9599993 <dyld_stub_binder+0x100928f8a>
              100001391:      48 89 df        movq    %rbx, %rdi
              100001394:      e8 f1 7b 92 00  callq   9599985 <dyld_stub_binder+0x100928f8a>
              100001399:      48 89 df        movq    %rbx, %rdi
              10000139c:      e8 e9 7b 92 00  callq   9599977 <dyld_stub_binder+0x100928f8a>
              1000013a1:      48 89 df        movq    %rbx, %rdi
              1000013a4:      e8 e1 7b 92 00  callq   9599969 <dyld_stub_binder+0x100928f8a>
              ... (snip 4800000 lines)
              100928f69:      48 89 df        movq    %rbx, %rdi
              100928f6c:      e8 19 00 00 00  callq   25 <dyld_stub_binder+0x100928f8a>
              100928f71:      48 89 df        movq    %rbx, %rdi
              100928f74:      e8 11 00 00 00  callq   17 <dyld_stub_binder+0x100928f8a>
              100928f79:      48 89 df        movq    %rbx, %rdi
              100928f7c:      e8 09 00 00 00  callq   9 <dyld_stub_binder+0x100928f8a>
              100928f81:      31 c0   xorl    %eax, %eax
              100928f83:      48 83 c4 08     addq    $8, %rsp
              100928f87:      5b      popq    %rbx
              100928f88:      5d      popq    %rbp
              100928f89:      c3      retq
              Disassembly of section __TEXT,__stubs:
              __stubs:
              100928f8a:      ff 25 80 00 00 00       jmpq    *128(%rip)
              Disassembly of section __TEXT,__stub_helper:
              __stub_helper:
              100928f90:      4c 8d 1d 69 00 00 00    leaq    105(%rip), %r11
              100928f97:      41 53   pushq   %r11
              100928f99:      ff 25 69 00 00 00       jmpq    *105(%rip)
              100928f9f:      90      nop
              100928fa0:      68 00 00 00 00  pushq   $0
              100928fa5:      e9 e6 ff ff ff  jmp     -26 <__stub_helper>
              
      2. 2

        0.4.0

        not that it would make a difference for this benchmark but 0.5.0 was released on monday

      1. 1

        This seems to stand in the old field of abiding by the letter of the law without adhering to the spirit of the law - I’ve always wondered how they could get away with this, and what provisions could prevent bad practice like this, if any without significant burden.