Mach7 icon indicating copy to clipboard operation
Mach7 copied to clipboard

Match on boost::variant is much slower than visitor based solution in Release build

Open solodon4 opened this issue 9 years ago • 3 comments

On Dec 12, 2014, at 15:23, Andrzej Krzemienski wrote:

Hi Yuriy, I have made a simple benchmark of visiting boost::variant with Mach7 vs using boost::static_visitor. Here is the code of the benchmark (fairly short): https://akrzemi1.wordpress.com/examples/mach7-benchmark/

I tested in GCC 4.8.2. (on Windows). For non-optimized version Mach7 is more-less 1.35 times faster. When compiled with -O2, boost::static_visitor is about 4.5 times faster. The results from a couple of runs (measured in clock ticks):

optimized:

mach7 visit 908 204 915 199 908 202 931 199 945 201 905 198

non-optimized:

mach7 visit 8304 11599 8575 11624 10144 11888 8394 12472 8252 11628 8591 11628

boost::static_visitor probably does something similar to Mach7: a switch on an integer.

Regards, Andrzej

solodon4 avatar Dec 17 '14 07:12 solodon4

Upon rerunning the same test recently, I get a more comparable results:

MSVC 14.0:
-------------
mach7   visit
2097    1270
2100    1299
2354    1300
2068    1277
2093    1279
2181    1371
2130    1264
2071    1278

GCC 9.4.2 (on Win):
-------------------
mach7   visit
1560    589 
1650    518
1577    577
1726    542
1712    630
1680    532
1615    600
1722    532

Either Mach7 got faster, or Boost.Variant slower, or I messed something with the previous benchmark. I run these with maximum optimizations and assertions disabled.

akrzemi1 avatar Feb 26 '16 23:02 akrzemi1

The issue hasn't been addressed yet, so the difference would still be there. Have you re-ran the experiment i patched above? I manually inlined both stuff as this was an issue affecting other experiments too - maybe that's the improvement you see. Did you test it with MSVC 14 before too or with MSVC 12?

solodon4 avatar Feb 27 '16 22:02 solodon4

Indeed. Previously I tested only GCC 4.8.2 on Windows (no MSVC at all). Now I am testing on GCC 4.8.2 (same GCC) and MSVC 14.0. I also can't remember if I disabled assertions when testing previously. I tested my original benchmark. Using your fixes (and my increased constants -- to make the test longer) I get these:

MSVC 14.0:
-------------
mach7   visit
1733    1242
1658    1235
1741    1291
1666    1236
1702    1237
1680    1233
1765    1241
1672    1238

GCC 9.4.2 (on Win):
-------------------
mach7   visit
1419    531
1389    483
1372    531
1373    499
1388    577
1451    640
1357    546
1388    515

They are a bit more in favor of Mach7: On MSVC Mach7 is slower 1.37 times. On GCC Mach7 is slower 2.58 times.

akrzemi1 avatar Feb 28 '16 23:02 akrzemi1