Skip to content

Commit 54d8d5b

Browse files
authored
quite faster rand(::MersenneTwister, ::Type{Float64}) etc... (#37916)
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`).
2 parents b8bc816 + ce6aa27 commit 54d8d5b

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
@@ -224,7 +224,7 @@ mt_setfull!(r::MersenneTwister) = r.idxF = 0
224224
mt_setempty!(r::MersenneTwister) = r.idxF = MT_CACHE_F
225225
mt_pop!(r::MersenneTwister) = @inbounds return r.vals[r.idxF+=1]
226226

227-
function gen_rand(r::MersenneTwister)
227+
@noinline function gen_rand(r::MersenneTwister)
228228
r.adv_vals = r.adv
229229
GC.@preserve r fill_array!(r, pointer(r.vals), length(r.vals), CloseOpen12())
230230
mt_setfull!(r)

0 commit comments

Comments
 (0)