Some benchmarks for switch jump tables using GoAWK

241 views
Skip to first unread message

ben...@gmail.com

unread,
May 1, 2022, 6:19:53 PM5/1/22
to golang-dev
Hi folks,

I've been doing some before/after performance testing of Keith Randall's CL to implement jump tables for the switch statement [1]. Thanks for your work on this, Keith and others! I'm testing using my GoAWK interpreter, whose virtual machine uses a big 86-case switch statement on the int32 opcode [2].

The good news is that for the two relatively real world uses of AWK there's a 3-4% speedup from jump tables. However, for whatever reason my less real world "sumloop" benchmark gets 5% slower. I also have a suite of 40 Go micro-benchmarks for GoAWK, and about half of them get 2-10% faster, however 3 of them get 7-14% slower.

In these results, "before" refers to using go1.19-dd97871282, before the switch jump tables commits, and "after" is go1.19-78bea702cd, after the switch jump tables commits.

Full results linked in the Gist [3], with a summary below:

* Go benchmark results: geometric mean of 40 benchmarks got 1.7% faster
* "countwords" got 3.4% faster: basically goawk '{ for (i=1; i<=NF; i++) counts[tolower($i)]++ }' (full script shown in Gist)
* "sumfield1" got 4.3% faster: goawk '{ s += $1 } END { print s }'
* "sumloop" got 4.8% SLOWER: goawk 'BEGIN { for (i=0; i<10000000; i++) sum += i+i+i+i+i }'

Firstly, I wanted to simply post these numbers. I think they're encouraging: there's a noticeable speedup for scripts that are most like what people use AWK for.

However, I'm unsure why some things get a fair bit slower. It's probably easiest to see and test in the IncrDecr benchmark (as well as the IfStatement and CondExpr benchmarks). How would I dig in further to why these got so much slower?

Cheers,
Ben.


Reply all
Reply to author
Forward
0 new messages