Skip to content

Commit ce6aa27

Browse files
committed
quite faster rand(::MersenneTwister, ::Type{Float64}) etc...
Generation of `Int64` just became faster than of `Float64` (#37914). Given that dSFMT produces natively `Float64`, and that generating a random `Float64` needs only 52 random bits, surely performance can be improved there. Just ask the `gen_rand` routine, which randomizes the cache for floats, to not inline, as it's unlikely to be called (once in a thousand). The speedups are about 1.8x for `rand(rng, Float64)`, 13% for `randn(rng, Float64)`, more than 1.9x for `rand(rng, Int32)` and smaller integers (including `Bool`).
1 parent 7d3dac4 commit ce6aa27

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/Random/src/RNGs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ mt_setfull!(r::MersenneTwister) = r.idxF = 0
230230
mt_setempty!(r::MersenneTwister) = r.idxF = MT_CACHE_F
231231
mt_pop!(r::MersenneTwister) = @inbounds return r.vals[r.idxF+=1]
232232

233-
function gen_rand(r::MersenneTwister)
233+
@noinline function gen_rand(r::MersenneTwister)
234234
r.adv_vals = r.adv
235235
GC.@preserve r fill_array!(r, pointer(r.vals), length(r.vals), CloseOpen12())
236236
mt_setfull!(r)

0 commit comments

Comments
 (0)