ronisbr / PrettyTables.jl

Print data in formatted tables.
MIT License
391 stars 38 forks source link

switch to Printf stdlib from Formatting #211

Closed ericphanson closed 12 months ago

ericphanson commented 12 months ago

closes https://github.com/ronisbr/PrettyTables.jl/issues/210

I noticed the original motivation for using Formatting.jl was performance, with a 100x5 table of floats being called out specifically as a benchmark. Since Julia 1.6, Printf has a fast dynamic formatter, and it seems to outperform Formatting.jl. With the benchmark

julia> using PrettyTables, BenchmarkTools

julia> data = Any[ f(a) for a = 1:100, f in (sind, cosd, tand, sind, sind)];

julia> @btime sprint(io -> pretty_table(io, data; formatters = ft_printf("%5.3f")));

on this branch I see

  667.000 μs (13377 allocations: 770.06 KiB)

whereas on master I see

  19.551 ms (32369 allocations: 1.58 MiB)

Additionally, all tests pass as-is, showing the compatibility of the approaches - I believe that is because PrettyTables is using just sprintf1 which is meant to be like @sprintf. (As a quick check, I put in a println("hi") in the new sprintf1 function to ensure it really is being called, and I could see it indeed is).

ronisbr commented 12 months ago

Thank you very much @ericphanson !! I had no idea how better Printf got in 1.6.

ronisbr commented 12 months ago

I will tag a new version as soon as I had access to my computer.

ericphanson commented 11 months ago

thanks for the quick response @ronisbr!