Testing some singleton implementations

Stanislav Blinov stanislav.blinov at gmail.com
Fri Jan 31 02:46:38 PST 2014


On Friday, 31 January 2014 at 10:39:19 UTC, Andrej Mitrovic wrote:
> On 1/31/14, Stanislav Blinov <stanislav.blinov at gmail.com> wrote:
>> You forgot to make the flag static for AtomicSingleton.
>
> Ah. It was copied verbatim from reddit, I guess we both missed 
> it.

Yeah, with D's verbosity in this cases it's easy to miss.

> Here's mine:
>
> $ dmd -release -inline -O -noboundscheck -unittest -run 
> singleton.d
>
> Test time for LockSingleton: 577.5 msecs.
> Test time for SyncSingleton: 9.25 msecs.
> Test time for AtomicSingleton: 159.75 msecs.
>
> Maybe ldc's optimizer is just much better at this?

It is :) 
http://forum.dlang.org/thread/lqmqsnucadaqlkxkoffc@forum.dlang.org

> In either case how come the atomic version is slower?

It may not be universally true, as Dmitry mentioned. On some 
platforms, TLS could be slow but atomics fast. I'm suspecting 
that on Windows TLS could be slower, actually.


More information about the Digitalmars-d mailing list