Skip to content

Instantly share code, notes, and snippets.

@flymanzhao
Last active September 17, 2024 06:41
Show Gist options
  • Select an option

  • Save flymanzhao/e0ded3b0cacf47babab85a95a56dcae3 to your computer and use it in GitHub Desktop.

Select an option

Save flymanzhao/e0ded3b0cacf47babab85a95a56dcae3 to your computer and use it in GitHub Desktop.
编译到Native的语言HelloWorld二进制大小 Windows

编译到Native的语言HelloWorld二进制大小

language size size (desc) flags
cpp/c++ 10,752 10.5 KB
nim 140,008 136 KB nim cpp -d:release --opt:size --out=hello_nim_cpp.exe hello.nim
nim 185,955 181 KB nim c -d:release --opt:size --out=hello_nim_c.exe hello.nim
d 507,392 495 KB dmd -O -release hello.d -of=hello_d_dmd.exe
d 462,848 452 KB ldc2 -O -release hello.d -of=hello_d_ldc_static.exe
d 10,752 10.5 KB ldc2 -O -release -link-defaultlib-shared hello.d -of=hello_d_ldc_dyn.exe
odin 247,808 242 KB odin build hello.odin -file -out:hello_odin.exe -o:size
go 863,744 843 KB go build -o hello_go.exe -ldflags="-s -w" hello.go
rust 152,064 148 KB cargo build --release

go

code

package main
func main() {
    // 注意,这里没有使用 fmt.Println可以减少文件大小
    print("Hello, World!\n")
}

compile cmd

编译命令

go build -o hello_go.exe -ldflags="-s -w" hello.go

result

hello_go.exe 843 KB (863,744 字节)

cpp/c++

code

#include <cstdio>

int main()
{
	printf("Hello World!");
}

compile cmd

msvc

cl /c /Zi /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /showIncludes /FC /errorReport:prompt hello.cpp
link.exe /ERRORREPORT:PROMPT /OUT:"x64\Release\hello.exe" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"x64\Release\hello.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /LTCGOUT:"x64\Release\hello.iobj" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"x64\Release\hello.lib" /MACHINE:X64 x64\Release\hello.obj

result

10.5 KB (10,752 字节)

nim

code

echo "Hello World!"

compile cmd

nim c -d:release --opt:size --out=hello_nim_c.exe hello.nim
nim cpp -d:release --opt:size --out=hello_nim_cpp.exe hello.nim

result

  • hello_nim_c.exe
    • 181 KB (185,955 字节)
  • hello_nim_cpp.exe
    • 136 KB (140,008 字节)

Odin

code

package main

import "core:fmt"

main :: proc() {
    fmt.println("Hello, World!")
}

compile cmd

odin build hello.odin -file -out:hello_odin.exe -o:size

result

242 KB (247,808 字节)

Rust

code

fn main() {
    println!("Hello, world!");
}

compile cmd

cargo build --release

result

148 KB (152,064 字节)

D

code

import std.stdio;

void main() {
    puts("Hello, World!");
}

compile cmd

dmd -O -release hello.d -of=hello_d_dmd.exe
ldc2 -O -release hello.d -of=hello_d_ldc_static.exe
ldc2 -O -release -link-defaultlib-shared hello.d -of=hello_d_ldc_dyn.exe

result

  • hello_d_dmd.exe
    • 495 KB (507,392 字节)
  • hello_d_ldc_static.exe
    • 452 KB (462,848 字节)
  • hello_d_ldc_dyn.exe
    • 10.5 KB (10,752 字节)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment