Skip to content

This is example that compare filesize using 'go build' command

License

Notifications You must be signed in to change notification settings

devlights/go-build-filesize-compare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-build-filesize-compare

This is example that compare filesize using 'go build' command

Gitpod ready-to-code

Run

Here's the result of running it on Gitpod.

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu Focal Fossa (development branch)"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ make
rm -f -r bin
mkdir -p bin
-----------------------------------------------------------
go build -o bin/build-normal main.go
go build "-ldflags=-s -w" -o bin/build-with-ldflags main.go
go build -trimpath -o bin/build-with-trimpath main.go
go build "-ldflags=-s -w" -trimpath -o bin/build-with-trimpath-ldflags main.go
upx --lzma -o bin/build-with-upx bin/build-with-trimpath-ldflags
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2018
UPX 3.95        Markus Oberhumer, Laszlo Molnar & John Reiser   Aug 26th 2018

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   1409024 ->    452852   32.14%   linux/amd64   build-with-upx                

Packed 1 file.
-----------------------------------------------------------
ls -1 bin/build* | xargs wc -c | head -n -1
2056769 bin/build-normal
1409024 bin/build-with-ldflags
2056769 bin/build-with-trimpath
1409024 bin/build-with-trimpath-ldflags
 452852 bin/build-with-upx
-----------------------------------------------------------
time -p bin/build-normal
hello Go[999]
[message]            hello Go
real 0.00
user 0.00
sys 0.00
-----------------------------------------------------------
time -p bin/build-with-ldflags
hello Go[999]
[message]            hello Go
real 0.00
user 0.00
sys 0.00
-----------------------------------------------------------
time -p bin/build-with-trimpath
hello Go[999]
[message]            hello Go
real 0.00
user 0.00
sys 0.00
-----------------------------------------------------------
time -p bin/build-with-trimpath-ldflags
hello Go[999]
[message]            hello Go
real 0.00
user 0.00
sys 0.00
-----------------------------------------------------------
time -p bin/build-with-upx
hello Go[999]
[message]            hello Go
real 0.08
user 0.06
sys 0.01

REFERENCES

About

This is example that compare filesize using 'go build' command

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published