Last active
December 4, 2021 13:49
-
-
Save aykevl/bc593ce06b22d64d8dcbb335a40a1e40 to your computer and use it in GitHub Desktop.
Size comparison for TinyGo
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
#!/bin/sh | |
# Note: use this script like so: | |
# git checkout dev | |
# ./sizecheck.sh > size0.txt | |
# git checkout some-feature-branch | |
# ./sizecheck.sh > size1.txt | |
# sizediff size0.txt size1.txt | |
for t in testdata/*.go; do echo host $t; tinygo build -o test.elf -size=short -no-debug $t; md5sum test.elf; done | |
echo | |
for t in testdata/*.go; do echo wasm $t; tinygo build -o wasm.wasm -size=short -no-debug $t; /bin/ls -l wasm.wasm; done | |
echo | |
for t in testdata/*.go; do echo microbit $t; tinygo build -o test.hex -target microbit -size=short $t; md5sum test.hex; done | |
echo | |
make smoketest XTENSA=0 |
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
#!/usr/bin/env python3 | |
import sys | |
class Comparison: | |
def __init__(self, command, code0, data0, bss0, code1, data1, bss1): | |
self.command = command | |
self.code0 = code0 | |
self.data0 = data0 | |
self.bss0 = bss0 | |
self.code1 = code1 | |
self.data1 = data1 | |
self.bss1 = bss1 | |
@property | |
def codediff(self): | |
return self.code1 - self.code0 | |
def readSizes(path): | |
sizes = [] | |
lines = open(path).readlines() | |
for i in range(len(lines)): | |
if not lines[i].strip().startswith('code '): | |
continue | |
# found a size header | |
code, data, bss = map(int, lines[i+1].split()[:3]) | |
command = lines[i-1].strip() | |
sizes.append({ | |
'command': command, | |
'code': code, | |
'data': data, | |
'bss': bss, | |
}) | |
return sizes | |
def main(): | |
path0 = sys.argv[1] | |
path1 = sys.argv[2] | |
sizes0 = readSizes(path0) | |
sizes1 = readSizes(path1) | |
comparisons = [] | |
for i in range(len(sizes0)): | |
if i >= len(sizes1): | |
print('%s has more commands than %s' % (path0, path1)) | |
print(' ', sizes0[i]['command']) | |
break | |
if sizes0[i]['command'] != sizes1[i]['command']: | |
print('not the same command!') | |
print(' ', sizes0[i]['command']) | |
print(' ', sizes1[i]['command']) | |
comparisons.append(Comparison(sizes0[i]['command'], sizes0[i]['code'], sizes0[i]['data'], sizes0[i]['bss'], sizes1[i]['code'], sizes1[i]['data'], sizes1[i]['bss'])) | |
if len(sizes0) < len(sizes1): | |
print('%s has more commands than %s' % (path1, path0)) | |
print(' ', sizes1[len(sizes0)]['command']) | |
comparisons.sort(key=lambda x: x.codediff) | |
totalCode0 = 0 | |
totalCode1 = 0 | |
totalDiff = 0 | |
print('before after diff') | |
for comparison in comparisons: | |
print('%6d %6d %6d %5.1f%% %s' % (comparison.code0, comparison.code1, comparison.codediff, comparison.codediff / comparison.code0 * 100, comparison.command)) | |
totalCode0 += comparison.code0 | |
totalCode1 += comparison.code1 | |
totalDiff += comparison.codediff | |
print('sum: %d (%.1f%%)' % (totalDiff, totalDiff / totalCode0 * 100)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice