On 04/15/2016 03:10 AM, Andrzej Krzemienski wrote: [snip]
Thank you for putting it this way. Ultimately my goal is to compare two ways of representing a (mathematical) expression tree. I tried one with OO-based virtual dispatch:
``` struct AdditioNode : NodeInterface { unique_ptr<NodeInterface> leftSubexpression, rightSubexpression; double eval() override; }; // etc... ```
And storing variants in a vector and representing links to subnodes as indexes:
``` struct Addition { int leftSubexpression, rightSubexpression; };
using Node = variant
; using ExpressionTree = vector<Node>; ``` I haven't done any profiling yet, but my benchmarks show, the former one (with virtual interfaces) is about twice faster. I found it quite surprising.
Other people got similar surprising performance results: http://stackoverflow.com/questions/11906741/boost-variant-vs-virtual-interfa... -regards, Larry