Skip to content

Instantly share code, notes, and snippets.

@sorear
Last active March 18, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorear/94abbe432efe0d57f31be05a8e01c930 to your computer and use it in GitHub Desktop.
Save sorear/94abbe432efe0d57f31be05a8e01c930 to your computer and use it in GitHub Desktop.
Static code size comparison of go backends (b53f0f8c + riscv64 patches)
TEXT SEGMENT SIZES FOR GO CMD AND X BINARIES RELATIVE TO AMD64
386 amd64 arm arm64 mips mips64 ppc64 riscv s390x
golang.org/x/blog/blog 79.4 100.0 82.7 81.4 99.4 101.8 87.2 53.5 113.1 100%=3.30 MB
golang.org/x/blog/content/context/server 79.6 100.0 83.0 81.4 99.5 101.8 87.1 53.6 112.9 100%=2.95 MB
golang.org/x/blog/content/survey2016 85.3 100.0 95.4 90.2 108.8 113.0 94.4 59.9 123.1 100%=0.64 MB
golang.org/x/blog/support/racy 85.4 100.0 96.4 90.2 108.6 113.1 94.2 59.4 123.5 100%=0.50 MB
golang.org/x/exp/ebnflint 84.7 100.0 95.0 89.9 108.4 112.7 94.0 59.2 122.7 100%=0.63 MB
golang.org/x/exp/io/i2c/example/displayip 84.4 100.0 94.4 89.3 108.2 112.2 94.0 59.0 122.2 100%=0.63 MB
golang.org/x/mobile/cmd/gobind 82.0 100.0 85.7 84.4 101.6 104.8 89.2 54.9 116.3 100%=2.60 MB
golang.org/x/mobile/cmd/gomobile 80.9 100.0 83.2 82.4 99.2 102.3 87.6 54.1 113.4 100%=3.82 MB
golang.org/x/net/http2/h2i 79.3 100.0 82.9 80.6 99.0 101.2 86.4 54.3 112.4 100%=2.25 MB
golang.org/x/review/git-codereview 79.3 100.0 82.8 80.9 99.1 101.5 86.5 53.5 113.2 100%=2.39 MB
golang.org/x/talks/2014/organizeio 85.4 100.0 96.4 90.2 108.6 113.1 94.2 59.4 123.5 100%=0.50 MB
golang.org/x/talks/2014/research2 84.9 100.0 95.3 89.5 108.1 112.5 94.0 59.5 123.0 100%=0.55 MB
golang.org/x/talks/2014/taste 79.3 100.0 83.0 80.7 99.2 101.3 86.4 53.5 112.8 100%=2.11 MB
golang.org/x/talks/2015/keeping-up 85.3 100.0 101.9 89.4 111.3 114.9 94.9 61.2 123.0 100%=0.31 MB
golang.org/x/talks/2016/applicative 85.3 100.0 95.8 89.8 108.9 112.8 94.3 59.7 123.1 100%=0.56 MB
golang.org/x/talks/2016/state-of-go/runtime 85.4 100.0 96.6 90.2 108.6 113.1 94.2 59.4 123.5 100%=0.50 MB
golang.org/x/text/cmd/gotext 82.0 100.0 86.9 85.9 103.6 107.0 90.8 55.9 118.7 100%=2.29 MB
golang.org/x/text/collate/tools/colcmp 82.2 100.0 88.8 86.8 106.2 109.6 93.1 58.1 118.9 100%=1.53 MB
golang.org/x/tools/cmd/benchcmp 85.4 100.0 95.8 90.4 108.5 112.9 94.2 59.5 123.1 100%=0.62 MB
golang.org/x/tools/cmd/bundle 82.3 100.0 87.7 86.1 103.9 107.2 90.8 56.0 119.3 100%=1.97 MB
golang.org/x/tools/cmd/callgraph 82.2 100.0 86.3 86.0 102.6 106.3 90.2 55.5 118.5 100%=2.63 MB
golang.org/x/tools/cmd/cover 82.2 100.0 88.0 86.7 104.8 108.4 91.9 56.8 119.5 100%=1.73 MB
golang.org/x/tools/cmd/digraph 85.3 100.0 95.5 90.1 108.2 112.5 93.9 59.5 122.5 100%=0.61 MB
golang.org/x/tools/cmd/eg 82.3 100.0 87.6 86.1 103.8 107.1 90.7 55.9 119.3 100%=1.99 MB
golang.org/x/tools/cmd/fiximports 82.6 100.0 88.9 87.2 105.3 108.9 92.0 56.9 120.6 100%=1.44 MB
golang.org/x/tools/cmd/godex 82.8 100.0 88.5 86.9 104.8 108.0 91.5 56.4 120.2 100%=1.82 MB
golang.org/x/tools/cmd/godoc 80.2 100.0 82.9 82.5 99.7 102.6 87.8 53.9 114.1 100%=5.59 MB
golang.org/x/tools/cmd/goimports 82.6 100.0 88.8 86.9 105.2 108.5 92.0 56.8 120.4 100%=1.62 MB
golang.org/x/tools/cmd/gomvpkg 81.9 100.0 86.6 85.4 103.0 106.3 90.1 55.4 118.1 100%=2.22 MB
golang.org/x/tools/cmd/gorename 82.2 100.0 87.3 85.8 103.5 106.8 90.5 55.7 118.9 100%=2.07 MB
golang.org/x/tools/cmd/goyacc 83.6 100.0 91.4 88.9 106.6 111.4 93.1 58.5 120.5 100%=0.98 MB
golang.org/x/tools/cmd/guru 81.8 100.0 85.7 85.5 102.4 106.0 90.1 55.4 118.0 100%=3.12 MB
golang.org/x/tools/cmd/heapview 79.5 100.0 83.2 80.8 99.5 101.5 86.5 53.6 112.9 100%=2.18 MB
golang.org/x/tools/cmd/html2article 83.4 100.0 92.9 89.5 108.5 113.0 95.0 59.3 124.7 100%=0.89 MB
golang.org/x/tools/cmd/present 79.6 100.0 82.8 81.9 99.7 102.2 87.4 53.7 113.6 100%=3.50 MB
golang.org/x/tools/cmd/ssadump 82.3 100.0 86.6 86.0 103.1 106.6 90.3 55.9 118.5 100%=2.73 MB
golang.org/x/tools/cmd/stress 83.3 100.0 92.4 88.8 106.9 111.5 93.5 58.5 123.0 100%=0.82 MB
golang.org/x/tools/cmd/stringer 82.4 100.0 87.6 86.0 104.0 107.1 90.7 55.9 119.0 100%=2.19 MB
golang.org/x/tools/cmd/tip 79.4 100.0 82.6 80.7 99.0 101.2 86.4 53.4 112.5 100%=2.55 MB
golang.org/x/tools/cmd/toolstash 83.2 100.0 91.8 88.3 106.5 110.9 93.1 58.1 122.3 100%=0.88 MB
cmd/addr2line 84.8 100.0 92.0 88.1 107.0 110.5 93.1 58.9 120.7 100%=1.02 MB
cmd/api 82.5 100.0 88.3 86.7 104.6 107.8 91.3 56.1 120.0 100%=1.79 MB
cmd/asm 83.5 100.0 94.5 91.3 108.9 113.7 94.1 65.0 124.2 100%=1.72 MB
cmd/cgo 83.5 100.0 88.8 86.1 103.7 107.5 90.7 56.9 118.1 100%=1.42 MB
cmd/compile 84.7 100.0 91.0 86.5 105.8 107.9 90.5 59.0 122.0 100%=6.76 MB
cmd/cover 82.2 100.0 88.0 86.7 104.8 108.4 91.9 56.8 119.5 100%=1.74 MB
cmd/disas 84.2 100.0 93.7 89.4 107.7 112.0 93.8 58.9 122.7 100%=0.73 MB
cmd/dist 82.6 100.0 89.9 87.5 105.9 110.5 92.7 58.3 120.2 100%=1.14 MB
cmd/doc 82.6 100.0 89.2 87.2 105.3 108.9 92.0 56.9 120.9 100%=1.38 MB
cmd/fix 83.2 100.0 90.7 88.0 106.1 110.5 92.6 57.7 120.7 100%=0.98 MB
cmd/go 79.7 100.0 82.2 81.2 98.5 101.2 86.5 53.5 112.7 100%=3.91 MB
cmd/gofmt 82.6 100.0 89.9 87.7 106.1 110.2 92.9 57.4 121.8 100%=1.23 MB
cmd/link 84.7 100.0 91.6 86.9 106.2 108.3 91.4 58.2 118.6 100%=1.97 MB
cmd/nm 84.8 100.0 92.0 88.1 106.9 110.5 93.0 59.0 120.5 100%=1.00 MB
cmd/objdump 84.0 100.0 91.0 87.5 106.5 110.1 92.9 58.4 121.2 100%=1.15 MB
cmd/pack 84.6 100.0 94.8 90.0 108.1 112.7 94.0 59.6 122.7 100%=0.62 MB
cmd/pprof 80.3 100.0 83.3 81.7 100.0 102.2 87.4 53.9 113.5 100%=3.56 MB
cmd/trace 79.8 100.0 83.2 81.7 99.9 102.2 87.4 53.8 113.4 100%=3.33 MB
cmd/vet 82.1 100.0 87.2 85.8 103.7 107.0 90.6 56.0 118.9 100%=2.39 MB
-geometric mean- 82.6 100.0 89.2 86.3 104.5 108.0 91.2 57.0 119.1
package main
import (
"fmt"
"log"
"math"
"os"
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
"text/tabwriter"
)
const (
packages = "golang.org/... cmd"
architectures = "riscv s390x ppc64 386 amd64 arm arm64 mips mips64"
index = "amd64"
)
func main() {
list, err := exec.Command("go", append([]string{"list", "-f", "{{.ImportPath}} {{.Target}}"}, strings.Split(packages, " ")...)...).Output()
if err != nil {
log.Fatal(err)
}
archList := strings.Split(architectures, " ")
sort.Strings(archList)
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprint(tw, "TEXT SEGMENT SIZES FOR GO CMD AND X BINARIES RELATIVE TO AMD64\n\n")
fmt.Fprint(tw, "\t")
for _, arch := range archList {
fmt.Fprintf(tw, "%s\t", arch)
}
fmt.Fprint(tw, "\n")
fmt.Fprint(tw, "\t")
for range archList {
fmt.Fprintf(tw, "\t")
}
fmt.Fprint(tw, "\n")
scrapeText := regexp.MustCompile(`\.text\s+([0-9a-f]+)`)
geo := make(map[string]float64)
count := 0
pkg:
for _, line := range strings.Split(string(list), "\n") {
if line == "" {
continue
}
split := strings.Split(line, " ")
if strings.HasSuffix(split[1], ".a") {
continue
}
path := split[0]
sizes := make(map[string]int64)
for _, arch := range archList {
tmp := "/tmp/" + strings.Replace(path, "/", "-", -1) + "." + arch
cmd := exec.Command("go", "install", path)
cmd.Env = append(os.Environ(), "GOARCH="+arch)
out, err := cmd.CombinedOutput()
if err != nil {
continue pkg
}
cmd = exec.Command("go", "build", "-o", tmp, path)
cmd.Env = append(os.Environ(), "GOARCH="+arch)
out, err = cmd.CombinedOutput()
if err != nil {
continue pkg
}
cmd = exec.Command("objdump", "-h", tmp)
objout, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(string(out), err)
}
sizes[arch], _ = strconv.ParseInt(string(scrapeText.FindSubmatch(objout)[1]), 16, 0)
geo[arch] += math.Log(float64(sizes[arch]))
}
fmt.Fprintf(tw, "%s \t", path)
for _, arch := range archList {
fmt.Fprintf(tw, "%5.1f\t", float64(sizes[arch])*100/float64(sizes[index]))
}
fmt.Fprintf(tw, "100%%=%.2f MB\t", float64(sizes[index])/1e6)
fmt.Fprint(tw, "\n")
count++
//if count == 3 {
// break
//}
}
fmt.Fprintf(tw, "-geometric mean-\t")
for _, arch := range archList {
fmt.Fprintf(tw, "%5.1f\t", math.Exp((geo[arch]-geo[index])/float64(count))*100)
}
fmt.Fprint(tw, "\n")
tw.Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment