<div dir="ltr"><div dir="ltr">On Wed, Jul 28, 2021 at 11:41 PM hanabi1224 via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesday, 28 July 2021 at 16:26:49 UTC, drug wrote:<br>
> I profiled the provided example (not `FiberScheduler`) using <br>
> perf. Both dmd and ldc2 gave the same result - `void <br>
> filterInner(int, int)` took ~90% of the run time. The time was <br>
> divided between:<br>
>       `int std.concurrency.receiveOnly!(int).receiveOnly()` - 58%<br>
>       `void std.concurrency.send!(int).send(std.concurrency.Tid, <br>
> int)` - 31%<br>
><br>
> So most of the time is messages passing.<br>
><br>
> Between the fibers creating took very few time. Perf output <br>
> contains information only of `void <br>
> std.concurrency.FiberScheduler.create(void delegate()).wrap()` <br>
> which took less than 0.5%. But I wouldn't say that I did the <br>
> profiling ideally so take it with a grain of salt.<br>
<br>
Very interesting findings! After making the Fiber fix, I also <br>
made profiling with valgrind, the result shows MessageBox related <br>
staff contributes to ~13.7% of total cycles, swapContex related <br>
staff add up to a larger percentage (My rough estimation is <br>
 >50%), I'd like to share the result svg but did not figure out <br>
how to upload here.<br></blockquote><div><br></div><div>I have rewrite it to be same as dart version</div><div><br></div><div>import std;<br><br>void main(string[] args) {<br>    auto n = args.length > 1 ? args[1].to!int() : 5;<br>    <br>    auto r = new Generator!int(<br>    {<br>        for(auto i = 2;;i++)<br>            yield(i);<br>    });<br>    <br>    for(auto i=0;i<n;i++)<br>    {<br>                <br>        auto prime = r.front;<br>        writeln(prime);<br>        r = filter(r, prime);<br>        <br>    }        <br>  <br>}<br><br>Generator!int filter(Generator!int input, int prime)<br>{<br>  <br>    return new Generator!int(<br>    {        <br>        while (input.empty is false)<br>        {    <br>            input.popFront();  <br>            auto i = input.front;<br>            if (i % prime != 0)<br>            {<br>                yield(i);<br>            }<br>        }<br>    });<br>}<br></div></div></div>