Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outline length assert in default_rng(tid) #34237

Merged
merged 1 commit into from
Jan 2, 2020
Merged

Conversation

KristofferC
Copy link
Member

Ref #34216

Benchmark

# export JULIA_NUM_THREADS=4
using BenchmarkTools, Random, Base.Threads

function par_pi(n::Int)
    hits = zeros(Int, nthreads())
    @threads for i in 1:n
        x, y = rand(), rand()
        hits[threadid()] += (x^2 + y^2 <= 1)
    end

    4.0 * sum(hits) / n
end
@btime par_pi(10_000_000)

master:

168.895 ms (24 allocations: 2.83 KiB)

PR:

 83.366 ms (24 allocations: 2.83 KiB)

@KristofferC KristofferC added performance Must go faster randomness Random number generation and the Random stdlib labels Jan 2, 2020
@KristofferC KristofferC requested a review from vtjnash January 2, 2020 16:18
@KristofferC KristofferC changed the title outline rng length assert outline length assert in default_rng(tid) Jan 2, 2020
@vtjnash
Copy link
Member

vtjnash commented Jan 2, 2020

Good find! I thought I had already beat on this as much as was possible.

@jebej
Copy link
Contributor

jebej commented Jan 2, 2020

Is the outlining trick for fixing performance when something throws an exception something that will be fixed? It seems unsustainable to do this in every single case.

@Keno
Copy link
Member

Keno commented Jan 2, 2020

It's a micro-optimization that doesn't usually matter. That said, it would be nice to do this automatically eventually.

@JeffBezanson JeffBezanson merged commit 53ba0cc into master Jan 2, 2020
@JeffBezanson JeffBezanson deleted the kc/rng_outline branch January 2, 2020 23:13
@KristofferC KristofferC mentioned this pull request Jan 8, 2020
28 tasks
KristofferC added a commit that referenced this pull request Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants