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

Regression: e.g. rand(100) a little slower #30529

Closed
PallHaraldsson opened this issue Dec 28, 2018 · 3 comments
Closed

Regression: e.g. rand(100) a little slower #30529

PallHaraldsson opened this issue Dec 28, 2018 · 3 comments
Labels
performance Must go faster randomness Random number generation and the Random stdlib

Comments

@PallHaraldsson
Copy link
Contributor

PallHaraldsson commented Dec 28, 2018

rand() is a bit faster on Julia 1.2, so that's a good thing, while rand(1) up to rand(100) is slower, so it may be regarding allocation[s], not be about rand?

First Julia 1.2 (yes, my laptop is a bit loaded (with Firefox running) and is very old, can anyone replicate on recent hardware?):

julia> @btime rand(1);
  97.928 ns (1 allocation: 96 bytes)

julia> @btime rand(1);
  98.043 ns (1 allocation: 96 bytes)

julia> @btime rand(1);
  98.409 ns (1 allocation: 96 bytes)

julia> @btime rand(10);
  130.490 ns (1 allocation: 160 bytes)

julia> @btime rand(100);
  579.181 ns (1 allocation: 896 bytes)

julia> @btime rand(100);
  564.536 ns (1 allocation: 896 bytes)

julia> @btime rand();
  7.411 ns (0 allocations: 0 bytes)

julia> @btime rand();
  7.480 ns (0 allocations: 0 bytes)

julia> versioninfo()
Julia Version 1.2.0-DEV.55
Commit 7acb991b98 (2018-12-21 23:33 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM)2 Duo CPU     T8100  @ 2.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, penryn)

Older Julia:

julia> @btime rand();
  11.255 ns (0 allocations: 0 bytes)

julia> @btime rand();
  11.325 ns (0 allocations: 0 bytes)

julia> @btime rand(1);
  78.665 ns (1 allocation: 96 bytes)

julia> @btime rand(1);
  78.214 ns (1 allocation: 96 bytes)

julia> @btime rand(10);
  114.000 ns (1 allocation: 160 bytes)

julia> @btime rand(100);
  489.624 ns (1 allocation: 896 bytes)

julia> @btime rand(100);
  481.225 ns (1 allocation: 896 bytes)

julia> versioninfo()
Julia Version 0.5.2
Commit f4c6c9d4bb (2017-05-06 16:34 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM)2 Duo CPU     T8100  @ 2.10GHz
  WORD_SIZE: 64
  BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Penryn)
  LAPACK: liblapack.so.3
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, penryn)

Then this form is faster for Julia 1.2 (and a bit faster than same for Julia 0.5, so I think I confimed not really about rand):

julia> @btime rand!(rng, a);
  378.034 ns (0 allocations: 0 bytes)

julia> @btime rand!(rng, a);
  374.184 ns (0 allocations: 0 bytes)

julia> @btime rand!(rng, a, 100);  # This worked in Julia 0.5, a is 100-element sized.
ERROR: ArgumentError: Sampler for this object is not defined
@inkydragon
Copy link
Member

rand() works fine in my computer @1.0.3&0.7

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)

julia> @btime rand(1);
  48.178 ns (1 allocation: 96 bytes)

julia> @btime rand(1);
  48.380 ns (1 allocation: 96 bytes)

julia> @btime rand(10);
  61.366 ns (1 allocation: 160 bytes)

julia> @btime rand(100);
  349.239 ns (1 allocation: 896 bytes)

julia> @btime rand(100);
  333.566 ns (1 allocation: 896 bytes)

julia> @btime rand();
  5.300 ns (0 allocations: 0 bytes)

julia> @btime rand();
  5.300 ns (0 allocations: 0 bytes)

julia>
julia> versioninfo()
Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)

julia> @btime rand(1);
  91.113 ns (1 allocation: 96 bytes)

julia> @btime rand(1);
  91.488 ns (1 allocation: 96 bytes)

julia> @btime rand(10);
  114.753 ns (1 allocation: 160 bytes)

julia> @btime rand(100);
  355.185 ns (1 allocation: 896 bytes)

julia> @btime rand(100);
  202.945 ns (1 allocation: 896 bytes)

julia> @btime rand();
  10.009 ns (0 allocations: 0 bytes)

julia> @btime rand();
  9.009 ns (0 allocations: 0 bytes)

julia>

@mbauman mbauman added performance Must go faster randomness Random number generation and the Random stdlib labels Dec 31, 2018
@xanfus
Copy link

xanfus commented Jan 1, 2019

No regression.

Julia Version 0.7.0
Commit a4cb80f (2018-08-08 06:46 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, sandybridge)

@btime rand(100);
  352.276 ns (1 allocation: 896 bytes)

Julia Version 1.2.0-DEV.75
Commit 8221c87* (2018-12-31 18:52 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, sandybridge)

@btime rand(100);
  247.824 ns (1 allocation: 896 bytes)

rand(1) takes 58-59 ns in both setups. I can't add BenchmarkTools to 0.5.2. I can add it to 1.0+. Why some actions continue to use proxies despite system-wide tweaks performed?

@ViralBShah
Copy link
Member

ViralBShah commented Jan 7, 2019

I benchmarked 0.6 and 1.0.3. I note that rand() and rand(100) take about the same time, whereas rand(1) is about 15% faster in 0.6. That suggests that this does not have to do with the RNG, and with small arrays. I have opened #30623 about this slowness, which is demonstrated with a simpler example.

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

No branches or pull requests

5 participants