Hacker News new | ask | show | jobs
by _paulc 2363 days ago
As it's not on Drew's list:

Nim:

  $ cat hello.nim
  stdout.write("hello, world!\n")
Static (musl):

  $ nim --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc --passL:-static c -d:release hello.nim
  $ ldd ./hello
  not a dynamic executable

  Execution Time: 0m0.002s (real)
  Total Syscalls: 16
  Unique Syscalls: 8
  Size (KiB): 95K (78K stripped)
Dynamic (glibc):

  $ nim c -d:release hello.nim
  $ ldd ./hello
  linux-vdso.so.1 =>  (0x00007ffc994b6000)
  libdl.so.2 => /lib64/libdl.so.2 (0x00007f7c88785000)
  libc.so.6 => /lib64/libc.so.6 (0x00007f7c883b8000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f7c88989000)

  Execution Time: 0m0.002s (real)
  Total Syscalls: 42
  Unique Syscalls: 13
  Size (KiB): 91K (79K stripped)
Which I think is actually pretty reasonable for a high-level GC'd language.
3 comments

"Size (KiB): 95K (78K stripped)"

Seems suspicious that lines up with the 95.9 KiB the author listed for C + GCC + musl static build even though the author says they stripped the binary after. I think they might have copied the wrong number into the table :).

The author was counting the size of dynamic as binary + dynamically linked files. Should be about the same as the c dynamic ones in the table in this case anyways but just a note to anyone else running their own tests.

Nim compiles to C
When testing with glibc, I got further improvements when I used echo instead of stdout.write, and also even more with

    -d:danger --opt:size
On lobste.rs, someone also listed results for OCaml and they were quite nice IMO too.
Curious if the generated C is any different for nim's echo as opposed to stdout.write().