{"id":16105874,"url":"https://github.com/devlights/go-build-filesize-compare","last_synced_at":"2025-04-06T03:13:40.597Z","repository":{"id":149716563,"uuid":"305540685","full_name":"devlights/go-build-filesize-compare","owner":"devlights","description":"This is example that compare filesize using 'go build' command","archived":false,"fork":false,"pushed_at":"2020-10-21T10:39:07.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-12T08:58:43.564Z","etag":null,"topics":["go","upx"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devlights.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-19T23:50:28.000Z","updated_at":"2022-08-17T07:42:43.000Z","dependencies_parsed_at":"2023-04-14T07:32:00.653Z","dependency_job_id":null,"html_url":"https://github.com/devlights/go-build-filesize-compare","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fgo-build-filesize-compare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fgo-build-filesize-compare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fgo-build-filesize-compare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fgo-build-filesize-compare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlights","download_url":"https://codeload.github.com/devlights/go-build-filesize-compare/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427012,"owners_count":20937214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","upx"],"created_at":"2024-10-09T19:10:58.977Z","updated_at":"2025-04-06T03:13:40.582Z","avatar_url":"https://github.com/devlights.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-build-filesize-compare\nThis is example that compare filesize using 'go build' command\n\n[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/devlights/go-build-filesize-compare)\n\n## Run\n\nHere's the result of running it on Gitpod.\n\n```sh\n$ cat /etc/os-release\nNAME=\"Ubuntu\"\nVERSION=\"20.04 LTS (Focal Fossa)\"\nID=ubuntu\nID_LIKE=debian\nPRETTY_NAME=\"Ubuntu Focal Fossa (development branch)\"\nVERSION_ID=\"20.04\"\nHOME_URL=\"https://www.ubuntu.com/\"\nSUPPORT_URL=\"https://help.ubuntu.com/\"\nBUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\nPRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\nVERSION_CODENAME=focal\nUBUNTU_CODENAME=focal\n```\n\n```sh\n$ make\nrm -f -r bin\nmkdir -p bin\n-----------------------------------------------------------\ngo build -o bin/build-normal main.go\ngo build \"-ldflags=-s -w\" -o bin/build-with-ldflags main.go\ngo build -trimpath -o bin/build-with-trimpath main.go\ngo build \"-ldflags=-s -w\" -trimpath -o bin/build-with-trimpath-ldflags main.go\nupx --lzma -o bin/build-with-upx bin/build-with-trimpath-ldflags\n                       Ultimate Packer for eXecutables\n                          Copyright (C) 1996 - 2018\nUPX 3.95        Markus Oberhumer, Laszlo Molnar \u0026 John Reiser   Aug 26th 2018\n\n        File size         Ratio      Format      Name\n   --------------------   ------   -----------   -----------\n   1409024 -\u003e    452852   32.14%   linux/amd64   build-with-upx                \n\nPacked 1 file.\n-----------------------------------------------------------\nls -1 bin/build* | xargs wc -c | head -n -1\n2056769 bin/build-normal\n1409024 bin/build-with-ldflags\n2056769 bin/build-with-trimpath\n1409024 bin/build-with-trimpath-ldflags\n 452852 bin/build-with-upx\n-----------------------------------------------------------\ntime -p bin/build-normal\nhello Go[999]\n[message]            hello Go\nreal 0.00\nuser 0.00\nsys 0.00\n-----------------------------------------------------------\ntime -p bin/build-with-ldflags\nhello Go[999]\n[message]            hello Go\nreal 0.00\nuser 0.00\nsys 0.00\n-----------------------------------------------------------\ntime -p bin/build-with-trimpath\nhello Go[999]\n[message]            hello Go\nreal 0.00\nuser 0.00\nsys 0.00\n-----------------------------------------------------------\ntime -p bin/build-with-trimpath-ldflags\nhello Go[999]\n[message]            hello Go\nreal 0.00\nuser 0.00\nsys 0.00\n-----------------------------------------------------------\ntime -p bin/build-with-upx\nhello Go[999]\n[message]            hello Go\nreal 0.08\nuser 0.06\nsys 0.01\n```\n\n## REFERENCES\n\n- [How to reduce compiled file size?](https://stackoverflow.com/questions/3861634/how-to-reduce-compiled-file-size)\n- [よく使うGoのBuildオプションと、UPXの圧縮がバイナリサイズにどの程度影響しているか調べた](https://qiita.com/laqiiz/items/80c103e719346f398b37)\n- [[v1.13版] goでスタティックバイナリを生成する方法](https://iguchitomokatsu.com/posts/how-to-make-static-binary-of-golang/)\n- [go tool link](https://golang.org/cmd/link/)\n- [go build (Compile packages and dependencies)](https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies)\n- [[Linux]wcコマンドの意外な使い方](https://cammy.co.jp/technical/2016/09/29/linuxwc%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E4%BB%A5%E5%A4%96%E3%81%AA%E4%BD%BF%E3%81%84%E6%96%B9/)\n- [Remove the last line from a file in Bash](https://stackoverflow.com/questions/4881930/remove-the-last-line-from-a-file-in-bash)\n- [デバッグ情報の歩き方](https://qiita.com/mhiramat/items/8df17f5113434e93ff0c)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlights%2Fgo-build-filesize-compare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlights%2Fgo-build-filesize-compare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlights%2Fgo-build-filesize-compare/lists"}