kalmarek / Arblib.jl

Thin, efficient wrapper around Arb library (http://arblib.org/)
MIT License
25 stars 6 forks source link

rand allocations #94

Open kalmarek opened 3 years ago

kalmarek commented 3 years ago

as observed in #82:

julia> @btime ArbMatrix(rand(Arb(prec=256), 100,100));
  4.085 ms (50007 allocations: 3.21 MiB)

julia> @btime ArbMatrix(rand(Arb, 100,100));
  4.507 ms (60005 allocations: 4.27 MiB)

i.e. 6 allocations per entry despite

julia> @btime Arb(rand($BigFloat));
  271.410 ns (5 allocations: 336 bytes)

Also:

julia> @btime ArbMatrix(rand($BigFloat, 100, 100));
  2.647 ms (30006 allocations: 2.06 MiB)

julia> @btime ArbMatrix(Arb.(rand($BigFloat, 100, 100)));
  3.293 ms (50008 allocations: 3.28 MiB)

julia> @btime ArbMatrix(rand($Arb, 100, 100));
  4.521 ms (60005 allocations: 4.27 MiB)

i.e. I botched random API :P

Joel-Dahne commented 3 years ago

With #108 we now have

julia> @btime ArbMatrix(rand(Arb(prec=256), 100,100));
  2.647 ms (50007 allocations: 3.21 MiB)

julia> @btime ArbMatrix(rand(Arb, 100,100));
  2.657 ms (50006 allocations: 3.21 MiB)

So they are equal!

We also have

julia> @btime ArbMatrix(rand($BigFloat, 100, 100));
  1.827 ms (30006 allocations: 2.06 MiB)

julia> @btime ArbMatrix(Arb.(rand($BigFloat, 100, 100)));
  1.988 ms (50008 allocations: 3.28 MiB)

julia> @btime ArbMatrix(rand($Arb, 100, 100));
  2.895 ms (50006 allocations: 3.21 MiB)

It's natural that the first one is faster since it avoids one copy of each Arb. The two last ones have the same number of allocations but they are not equally fast, I'm not entirely sure why this is the case.

Notice that we still have the same problems as before with Acb.

kalmarek commented 3 years ago

very well, thanks!