Testing some singleton implementations

Benjamin Thaut code at benjamin-thaut.de
Fri Jan 31 03:31:55 PST 2014


Am 31.01.2014 10:18, schrieb Stanislav Blinov:
> You forgot to make the flag static for AtomicSingleton. I'd also move
> the timing into the threads themselves, for fairness :)
>
> http://codepad.org/gvm3A88k
>
> Timings on my machine:
>
> ldc2 -unittest -release -O3:
>
> Test time for LockSingleton: 537 msecs.
> Test time for SyncSingleton: 2 msecs.
> Test time for AtomicSingleton: 2.25 msecs.
>
> dmd -unittest -release -O -inline:
>
> Test time for LockSingleton: 451.5 msecs.
> Test time for SyncSingleton: 7.75 msecs.
> Test time for AtomicSingleton: 99.75 msecs.
>

For x86 CPUs you don't really need MemoryOrder.acq as reads are atomic 
by default. So I replaced that with MemoryOrder.raw and named it 
AtomicSingletonRaw

On Windows 7:

dmd -unittest -release -O -inline -noboundscheck
Test time for LockSingleton: 299 msecs.
Test time for SyncSingleton: 5 msecs.
Test time for AtomicSingleton: 304 msecs.
Test time for AtomicSingletonRaw: 280 msecs.

ldc2 -release -unittest -O3
Test time for LockSingleton: 320 msecs.
Test time for SyncSingleton: 2 msecs.
Test time for AtomicSingleton: 271 msecs.
Test time for AtomicSingletonRaw: 209 msecs.

It seems that the SyncSingleton is supperior in all cases.



More information about the Digitalmars-d mailing list