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