Skip to content

Instantly share code, notes, and snippets.

@lfkdsk
Created January 29, 2024 10:30
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 lfkdsk/aa2b55fc4969d29625ec6b759322776e to your computer and use it in GitHub Desktop.
Save lfkdsk/aa2b55fc4969d29625ec6b759322776e to your computer and use it in GitHub Desktop.
import os, sys
import multiprocessing
import subprocess
bench = [
"BenchmarkBinaryTree",
"BenchmarkFannkuch11",
"BenchmarkFmtFprintfEmpty",
"BenchmarkFmtFprintfString",
"BenchmarkFmtFprintfInt",
"BenchmarkFmtFprintfIntInt",
"BenchmarkFmtFprintfPrefixedInt",
"BenchmarkFmtFprintfFloat",
"BenchmarkFmtManyArgs",
"BenchmarkGobDecode",
"BenchmarkGobEncode",
"BenchmarkGzip",
"BenchmarkGunzip",
"BenchmarkHTTPClientServer",
"BenchmarkJSONEncode",
"BenchmarkJSONDecode",
"BenchmarkMandelbrot",
"BenchmarkGoParse",
"BenchmarkRegexpMatchEasy0_32",
"BenchmarkRegexpMatchEasy0_1K",
"BenchmarkRegexpMatchEasy1_32",
"BenchmarkRegexpMatchEasy1_1K",
"BenchmarkRegexpMatchMedium_32",
"BenchmarkRegexpMatchMedium_1K",
"BenchmarkRegexpMatchHard_32",
"BenchmarkRegexpMatchHard_1K",
"BenchmarkRevcomp",
"BenchmarkTemplate",
"BenchmarkTimeParse",
"BenchmarkTimeFormat"
]
TO = "160s"
CNT = "20"
#TO = "20s"
#CNT = "1"
cmd0 = "GOAMD64=v4 timeout " + TO + " ../../../bin/go test -gcflags \"-beast=llvm=0 -d panic=1\" -count " + CNT + " -bench="
cmd3 = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/Onone.json\" timeout " + TO + " ../../../bin/go test -gcflags all=\"-beast=llvm=3 -d panic=1\" -count " + CNT + " -bench="
cmd3_opt = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/O3.json\" timeout " + TO + " ../../../bin/go test -gcflags all=\"-beast=llvm=3 -d panic=1\" -count " + CNT + " -bench="
cmd3_opt_inline = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/O3.json\" timeout " + TO + " ../../../bin/go test -gcflags all=\"-beast=llvm=3,inline=1 -d panic=1\" -count " + CNT + " -bench="
cmd3_opt_always_inline = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/O3.json\" timeout " + TO + " ../../../bin/go test -gcflags all=\"-beast=llvm=3,inline=2 -d panic=1\" -count " + CNT + " -bench="
cmd4 = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/Onone.json\" timeout " + TO + " ../../../bin/go test -gcflags \"-beast=llvm=4 -d panic=1\" -count " + CNT + " -bench="
cmd4_opt = "GOAMD64=v4 GO_LLVM_PASS_CONFIG=\"../../../src/cmd/compile/internal/llvm/O3.json\" timeout " + TO + " ../../../bin/go test -gcflags \"-beast=llvm=4 -d panic=1\" -count " + CNT + " -bench="
def task_function(cmd):
try:
print(f'Run: {cmd}\n')
result = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
return e.stderr.strip()
os.system("rm -f llvm*.txt")
def run_bench(name, cmd):
print(f"running {name}:")
commands = []
for b in bench:
commands.append(cmd + b)
with multiprocessing.Pool(processes=multiprocessing.cpu_count()) as pool, open(f'llvm{name}.txt', 'w') as out:
results = pool.map(task_function, commands)
for r in results:
if 'PASS' in r:
print("PASS")
out.write(f'{r}\n')
run_bench("0", cmd0)
run_bench("3", cmd3)
run_bench("3_opt", cmd3_opt)
run_bench("3_opt_inline", cmd3_opt_inline)
run_bench("3_opt_always_inline", cmd3_opt_always_inline)
# run_bench("4", cmd4)
# run_bench("4_opt", cmd4_opt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment