[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Adding the random mersenne twister to gst
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Adding the random mersenne twister to gst |
Date: |
Thu, 27 Jan 2011 01:17:28 +0100 |
committed thanks
Paolo
On Sun, Jan 9, 2011 at 20:27, Mathieu Suen <address@hidden> wrote:
> Hi All,
>
> Some time ago Paolo did post a message to see if we could
> change the rng because will fast it was making garbage.
>
> Thus Paolo did suggest to implement the Mersenne Twister.
> So here you can find an implementation of it:
> rev:
> c0a83d2 https://github.com/mathk/smalltalk/commit/c0a83d2
> a1f137b https://github.com/mathk/smalltalk/commit/a1f137b
> ab8cc96 https://github.com/mathk/smalltalk/commit/ab8cc96
> ed9360a https://github.com/mathk/smalltalk/commit/ed9360a
>
> For the time being I did a separate class namely RandomMT19937.
> only the #next differ from the original Random class.
> Now #next return a positive SmallInteger (30bit wise)
> so no object are allocated on 32bit and 64bit arch.
>
> I have made a tiny bench:
> address@hidden smalltalk $ cat BenchRand.st
> Eval [
> | n k r o |
> r := RandomMT19937 source.
> n := 100000.
> k := 500.
> o := OrderedCollection new.
> 1 to: n do: [:x |
> ((r between: 0 and: (n := n - 1)) < k
> ifTrue: [o add: x. k := k - 1]) notNil ].
>
> ]
> address@hidden smalltalk $ time gst BenchRand.st
>
> real 0m0.096s
> user 0m0.072s
> sys 0m0.012s
> address@hidden smalltalk $ cat BenchRand.st
> Eval [
> | n k r o |
> r := Random source.
> n := 100000.
> k := 500.
> o := OrderedCollection new.
> 1 to: n do: [:x |
> ((r between: 0 and: (n := n - 1)) < k
> ifTrue: [o add: x. k := k - 1]) notNil ].
>
> ]
> address@hidden smalltalk $ time gst BenchRand.st
> "Global garbage collection... done"
>
> real 0m0.308s
> user 0m0.276s
> sys 0m0.022s
> address@hidden smalltalk $
>
> Questions or comments are welcome.
> Thanks
>
> Mth
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> En finir avec le spam? Yahoo! Mail vous offre la meilleure protection
> possible contre les messages non sollicités
> http://mail.yahoo.fr Yahoo! Mail
>
> _______________________________________________
> help-smalltalk mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>
>