Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Aug 11, 2024
1 parent e18df73 commit a2dc250
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/benchmark-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Benchmark sonic
- name: Benchmark encoder/decoder
run: |
export SONIC_NO_ASYNC_GC=1
./scripts/bench.py -c -nr -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark(Encoder|Decoder)_(Generic|Binding)_Sonic' ./decoder"
- name: Benchmark ast
run: |
export SONIC_NO_ASYNC_GC=1
./scripts/bench.py -c -nr -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark(Get|Set)One_Sonic|BenchmarkParseSeven_Sonic' ./ast"
- name: Benchmark biz
run: |
export SONIC_NO_ASYNC_GC=1
export SONIC_BENCH_SINGLE=1
./scripts/bench.py -c -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark(Encoder|Decoder)_(Generic|Binding)_Sonic' ./decoder"
./scripts/bench.py -c -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark(Get|Set)One_Sonic|BenchmarkParseSeven_Sonic' ./ast"
./scripts/bench.py -c -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark' ./generic_test"
./scripts/bench.py -c -nr -t 0.05 "go test -run ^$ -count=10 -benchmem -bench 'Benchmark' ./generic_test"
26 changes: 15 additions & 11 deletions scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def compare(args):
return None

# get the current diff
(fd, diff) = tempfile.mkstemp()
run("git diff > %s"%diff)
if not args.norestore:
(fd, diff) = tempfile.mkstemp()
run("git diff > %s"%diff)

# early return if currrent is main branch.
print ("Current branch: %s"%(current_branch))
Expand All @@ -73,23 +74,25 @@ def compare(args):

# benchmark current branch
target = run_bench(args, "target")


# trying to switch to the latest main branch
run("git checkout -- .")

# trying to switch to the latest main branch
if current_branch != "main":
run("git checkout main")
run("git pull --allow-unrelated-histories origin main")
if not args.norestore:
run("git checkout main")
run("git pull --allow-unrelated-histories origin main")
else:
run("git reset --hard origin/main")

# benchmark main branch
main = run_bench(args, "main")
run("git checkout -- .")

# restore branch
if current_branch != "main":
run("git checkout %s"%(current_branch))

run("patch -p1 < %s" % (diff))
if not args.norestore:
if current_branch != "main":
run("git checkout %s"%(current_branch))
run("patch -p1 < %s" % (diff))

# diff the result
bench_diff(main, target, args.threshold)
Expand Down Expand Up @@ -166,6 +169,7 @@ def bench_diff(main, target, threshold=0.05):
def main():
argparser = argparse.ArgumentParser(description='Tools to test the performance. Example: ./bench.py "go test -bench=. ./..."')
argparser.add_argument('cmd', type=str, help='Golang benchmark command')
argparser.add_argument('-nr', type=bool, dest='norestore', default=False, help='not restore branch')
argparser.add_argument('-t', type=float, dest='threshold', default=0.1, help='diff bench threshold')
argparser.add_argument('-c', '--compare', dest='compare', action='store_true',
help='Compare the current branch with the main branch')
Expand Down

0 comments on commit a2dc250

Please sign in to comment.