Julia: Int and Float printing performance could be better

Created on 12 Feb 2019  路  5Comments  路  Source: JuliaLang/julia

Comparing the printing of Int64 and Int32 with Float64 and Float32, it seems that the former could be more efficient:

julia> @btime join(fill(1.0, 10^6), " ") evals=1 samples=1;
  159.393 ms (28 allocations: 11.63 MiB)

julia> @btime join(fill(1, 10^6), " ") evals=1 samples=1;
  151.988 ms (2000027 allocations: 101.18 MiB)
performance

Most helpful comment

Despite the allocations, the integer case seems to be slightly faster. Why is this a problem?

All 5 comments

Despite the allocations, the integer case seems to be slightly faster. Why is this a problem?

I would expect printing integers to be quite a bit faster. Isn't it a simpler task?

For example, here's a comparison of the same operation with kdb+/q (a high performance APL-like language, timings are in milliseconds):

julia> @btime join(fill(1.0, 10^6)) evals=1 samples=1;
  149.535 ms (28 allocations: 11.63 MiB)

julia> @btime join(fill(1, 10^6)) evals=1 samples=1;
  131.836 ms (2000024 allocations: 100.18 MiB)
q)\t raze string 1000000#1.0
42
q)\t raze string 1000000#1
13

(I removed the space to simplify the example.)

Ok, thanks, it is helpful to have a point of comparison. In fact it looks like both operations should be faster.

1.2:

julia> @btime join(fill(1.0, 10^6), " ") evals=1 samples=1;
  134.654 ms (1000027 allocations: 26.89 MiB)

julia> @btime join(fill(1, 10^6), " ") evals=1 samples=1;
  103.964 ms (2000026 allocations: 101.18 MiB)

master

julia> @btime join(fill(1.0, 10^6), " ") evals=1 samples=1;
  81.318 ms (2000027 allocations: 425.62 MiB)

julia> @btime join(fill(1, 10^6), " ") evals=1 samples=1;
  58.768 ms (2000026 allocations: 101.18 MiB)

More allocations, faster speed :)

I assume Ryu make the Float printing faster, despite (or because) the extra allocations it does. What made Int printing faster?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

musm picture musm  路  3Comments

sbromberger picture sbromberger  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments

StefanKarpinski picture StefanKarpinski  路  3Comments

felixrehren picture felixrehren  路  3Comments