Adding the random mersenne twister to gst

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding the random mersenne twister to gst

Mathieu Suen-2
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:
mathk@Nani 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 ].
   
]
mathk@Nani smalltalk $ time gst BenchRand.st

real 0m0.096s
user 0m0.072s
sys 0m0.012s
mathk@Nani 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 ].
   
]
mathk@Nani smalltalk $ time gst BenchRand.st
"Global garbage collection... done"

real 0m0.308s
user 0m0.276s
sys 0m0.022s
mathk@Nani 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
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Adding the random mersenne twister to gst

Paolo Bonzini-2
committed thanks

Paolo

On Sun, Jan 9, 2011 at 20:27, Mathieu Suen <[hidden email]> 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:
> mathk@Nani 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 ].
>
> ]
> mathk@Nani smalltalk $ time gst BenchRand.st
>
> real    0m0.096s
> user    0m0.072s
> sys     0m0.012s
> mathk@Nani 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 ].
>
> ]
> mathk@Nani smalltalk $ time gst BenchRand.st
> "Global garbage collection... done"
>
> real    0m0.308s
> user    0m0.276s
> sys     0m0.022s
> mathk@Nani 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
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk