<div class="gmail_quote">On Sun, Jul 29, 2012 at 6:43 PM, Dmitry Olshansky <span dir="ltr"><<a href="mailto:dmitry.olsh@gmail.com" target="_blank">dmitry.olsh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 29-Jul-12 18:17, Andrei Alexandrescu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 7/29/12 8:17 AM, Gor Gyolchanyan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
std.variant is so incredibly slow! It's practically unusable for<br>
anything, which requires even a tiny bit of performance.<br>
</blockquote>
<br>
You do realize you actually benchmark against a function that does<br>
nothing, right? Clearly there are ways in which we can improve<br>
std.variant to the point initialization costs assignment of two words,<br>
but this benchmark doesn't help. (Incidentally I just prepared a class<br>
at C++ and Beyond on benchmarking, and this benchmark makes a lot of the<br>
mistakes described therein...)<br>
<br>
<br>
Andrei<br>
</blockquote>
<br>
<br></div></div>
This should be more relevant then:<br>
<br>
//fib.d<br>
import std.datetime, std.stdio, std.variant;<br>
<br>
auto fib(Int)()<br>
{<br>
        Int a = 1, b = 1;<br>
        for(size_t i=0; i<100; i++){<br>
                Int c = a + b;<br>
                a = b;<br>
                b = c;<br>
        }<br>
        return a;       <br>
}<br>
<br>
void main()<br>
{<br>
        writeln(benchmark!(fib!int, fib!long, fib!Variant)(10_000));<br>
}<br>
<br>
<br>
dmd -O -inline -release fib.d<br>
<br>
Output:<br>
<br>
[TickDuration(197), TickDuration(276), TickDuration(93370107)]<br>
<br>
I'm horrified. Who was working on std.variant enhancements? Please chime in.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Dmitry Olshansky<br>
</font></span></blockquote></div><br>Thank you for demonstrating my point. :-)<br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>