Oh, my GoD! Goroutines on D
Jin
nin-jin at ya.ru
Sun Jun 14 22:57:25 UTC 2020
On Sunday, 14 June 2020 at 19:49:46 UTC, mw wrote:
> On Sunday, 14 June 2020 at 17:10:14 UTC, mw wrote:
>> Have you tried lock-free queue?
>>
>> https://www.liblfds.org/mediawiki/index.php?title=r7.1.1:Queue_(unbounded,_many_producer,_many_consumer)
>>
>> Java uses the same algorithm for ConcurrentLinkedQueue (in C
>> implementation).
>>
>> I tried some small examples with liblfds, got slightly better
>> performance than Java. Maybe we don’t want to reinvent the
>> wheels, esp the well tested ones.
>
> You can try it here:
>
> https://github.com/mingwugmail/liblfdsd
>
> only
> https://www.liblfds.org/mediawiki/index.php?title=r7.1.1:Queue_(bounded,_many_producer,_many_consumer) for now.
>
> ```
> received 100000000 messages in 4632 msec sum=4999999950000000
> speed=21588 msg/msec
> ```
My wheels are quite simple:
https://github.com/nin-jin/go.d/blob/master/source/jin/go/queue.d
I have written your bench
(https://github.com/mingwugmail/liblfdsd/blob/master/liblfds.dpp#L67) with go.d:
```
const int n = 100_000_000;
void threadProducer(Output!int queue)
{
foreach (int i; 0..n) {
queue.put(i);
}
}
void main()
{
Input!int queue;
go!threadProducer(queue.pair);
StopWatch sw;
sw.start();
long sum = 0;
foreach (p; queue)
{
sum += p;
}
sw.stop();
writefln("received %d messages in %d msec sum=%d speed=%d
msg/msec", n,
sw.peek.total!"msecs", sum, n / sw.peek.total!"msecs");
assert(sum == (n * (n - 1) / 2));
}
```
The code is simpler. On my laptop it gives:
```
> dub --quiet --build=release
received 100000000 messages in 10011 msec sum=4999999950000000
speed=9989 msg/msec
```
More information about the Digitalmars-d
mailing list