Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
solodon4 opened this issue Dec 17, 2014 · 3 comments
Assignees
Labels

Comments

@solodon4
Copy link
Owner

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 solodon4 added the bug label Dec 17, 2014
@solodon4 solodon4 self-assigned this Dec 17, 2014
solodon4 added a commit that referenced this issue Dec 17, 2014
…ne). This was scewing results before with regular visitors. The performance regression still exists. Issue #15
@akrzemi1
Copy link
Contributor

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.

@solodon4
Copy link
Owner Author

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?

@akrzemi1
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants