Created
December 5, 2018 03:56
-
-
Save yousong/638421064f2302d5730a6bda288696ed to your computer and use it in GitHub Desktop.
build time, executable size with varying number of func args, struct members
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
na() { | |
a_params=("a1 string") | |
a_vars=("a1") | |
a_args=("\"a1\"") | |
a_members=("a1 string") | |
for i in `seq 2 $n`; do | |
a_params+=(", a$i string") | |
a_vars+=(", a$i") | |
a_args+=(", \"a$i\"") | |
a_members+=("; a$i string") | |
done | |
} | |
f() { | |
cat <<EOF >f.go | |
package main | |
import "fmt" | |
func f(${a_params[*]}) { | |
fmt.Println(${a_vars[*]}) | |
} | |
func main() { | |
f(${a_args[*]}) | |
} | |
EOF | |
} | |
g() { | |
cat <<EOF >g.go | |
package main | |
import "fmt" | |
func g(a ...interface{}) { | |
fmt.Printf("%#v\n", a) | |
} | |
func main() { | |
g(${a_args[*]}) | |
} | |
EOF | |
} | |
h() { | |
cat <<EOF >h.go | |
package main | |
import "fmt" | |
type A struct { | |
${a_members[*]} | |
} | |
func h(a A) { | |
fmt.Printf("%#v\n", a) | |
} | |
func main() { | |
h(A{}) | |
} | |
EOF | |
} | |
i() { | |
cat <<EOF >i.go | |
package main | |
import "fmt" | |
type A struct { | |
${a_members[*]} | |
} | |
func i(a *A) { | |
fmt.Printf("%#v\n", a) | |
} | |
func main() { | |
i(&A{}) | |
} | |
EOF | |
} | |
n=1 | |
for i in `seq 1 15`; do | |
echo -n "$n" | |
na | |
for j in f g h i; do | |
$j | |
t=$(TIME=%E command time go build -o $j $j.go 2>&1 >/dev/null) | |
if [ "$?" -eq 0 ]; then | |
echo -n " $(stat -c %s $j)" | |
else | |
echo -n " 0" | |
fi | |
echo -n " $t" | |
done | |
echo "" | |
let n=n+n | |
done | |
rm -vf f g h i | |
rm -vf f.go g.go h.go i.go | |
# go1.11.2 | |
# | |
# 1 1906935 0:00.24 1923609 0:00.06 1923568 0:00.06 1923568 0:00.07 | |
# 2 1907035 0:00.23 1923750 0:00.24 1923650 0:00.24 1923650 0:00.25 | |
# 4 1907035 0:00.26 1923832 0:00.26 1923691 0:00.24 1923650 0:00.26 | |
# 8 1911131 0:00.24 1923996 0:00.26 1923691 0:00.24 1923650 0:00.25 | |
# 16 1911133 0:00.25 1924332 0:00.25 1923691 0:00.24 1923650 0:00.24 | |
# 32 1915229 0:00.24 1925004 0:00.23 1927787 0:00.24 1927746 0:00.25 | |
# 64 1923421 0:00.24 1930444 0:00.24 1935979 0:00.26 1931842 0:00.24 | |
# 128 1964383 0:00.24 1941354 0:00.26 1948267 0:00.24 1944130 0:00.25 | |
# 256 2091359 0:00.25 1955050 0:00.25 1972843 0:00.26 1968706 0:00.24 | |
# 512 2574687 0:00.26 1994730 0:00.25 2026091 0:00.26 2013762 0:00.25 | |
# 1024 4417889 0:00.33 2070020 0:00.26 2128491 0:00.26 2112066 0:00.25 | |
# 2048 11643233 0:00.40 2217476 0:00.27 2337387 0:00.31 2300482 0:00.27 | |
# 4096 40266081 0:00.86 2516484 0:00.30 2755179 0:00.32 2677314 0:00.33 | |
# 8192 154118497 0:03.01 3110404 0:00.31 3590763 0:00.53 3430978 0:00.51 | |
# 16384 0 0:37.51 4300534 0:01.60 5261931 0:01.28 4950594 0:01.37 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment