JuliaImages / DitherPunk.jl

Dithering algorithms in Julia.
MIT License
60 stars 3 forks source link

Faster `braille` printing #95

Closed adrhill closed 2 years ago

adrhill commented 2 years ago

Current release v3.0.3

julia> using DitherPunk

julia> A = rand(Bool, 1000, 1000);

julia> @benchmark braille($A; to_string=true)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  67.883 μs …  6.974 ms  ┊ GC (min … max): 0.00% … 98.66%
 Time  (median):     73.201 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   78.108 μs ± 94.868 μs  ┊ GC (mean ± σ):  1.69% ±  1.39%

  ▃▅▆██▇▆▅▃▃▂▁▁ ▁▂▁▁  ▁▁▃▁▂          ▁▁                       ▂
  █████████████████████████▆▇▇▆▆▆▇▇▇▇██▆██▇▆▇▆▅▆▅▄▁▁▅▆▅▅▅▄▁▃▄ █
  67.9 μs      Histogram: log(frequency) by time       136 μs <

 Memory estimate: 12.26 KiB, allocs estimate: 9.

julia> B = rand(Bool, 1000, 1000);

julia> @benchmark braille($B; to_string=true)
BenchmarkTools.Trial: 572 samples with 1 evaluation.
 Range (min … max):  6.939 ms … 41.132 ms  ┊ GC (min … max): 0.00% … 71.59%
 Time  (median):     7.974 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   8.700 ms ±  3.446 ms  ┊ GC (mean ± σ):  4.59% ±  9.10%

  ▃▇█▆▅▄▄▃▁                                                   
  ███████████▇▆▅▁▄▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▁▁▄▁▁▁▁▄▁▁▁▁▁▄ ▇
  6.94 ms      Histogram: log(frequency) by time     27.7 ms <

 Memory estimate: 1.03 MiB, allocs estimate: 16.

This PR

julia> using DitherPunk

julia> A = rand(Bool, 100, 100);

julia> @benchmark braille($A; to_string=true)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  46.578 μs …  4.979 ms  ┊ GC (min … max): 0.00% … 98.68%
 Time  (median):     48.045 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   51.144 μs ± 49.861 μs  ┊ GC (mean ± σ):  0.96% ±  0.99%

  ▂█▇▅▃▆▅▄▃▁▂                 ▂▁ ▃▃                      ▁▁   ▂
  █████████████▆█▇▇▆▆▆▅▄▆▄▅▆▄▇█████▇▆▇▆▅▇▇▇▆▆▅▄▄▆▅▃▄▅▇▄▁▄███▅ █
  46.6 μs      Histogram: log(frequency) by time      77.2 μs <

 Memory estimate: 7.20 KiB, allocs estimate: 8.

julia> B = rand(Bool, 1000, 1000);

julia> @benchmark braille($B; to_string=true)
BenchmarkTools.Trial: 907 samples with 1 evaluation.
 Range (min … max):  4.752 ms … 39.664 ms  ┊ GC (min … max): 0.00% … 84.57%
 Time  (median):     5.144 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   5.492 ms ±  1.664 ms  ┊ GC (mean ± σ):  2.29% ±  6.42%

       █▄                                                     
  ▄▆█▆████▅▅▄▄▃▃▄▄▃▃▃▃▃▃▃▃▃▂▃▃▃▃▂▂▂▂▂▂▂▂▂▂▁▂▂▁▂▂▂▂▂▂▂▂▂▁▂▁▁▂ ▃
  4.75 ms        Histogram: frequency by time        8.13 ms <

 Memory estimate: 570.70 KiB, allocs estimate: 14.
codecov[bot] commented 2 years ago

Codecov Report

Merging #95 (7424412) into master (d723bd1) will decrease coverage by 0.02%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
- Coverage   97.95%   97.93%   -0.03%     
==========================================
  Files          12       12              
  Lines         293      290       -3     
==========================================
- Hits          287      284       -3     
  Misses          6        6              
Impacted Files Coverage Δ
src/braille.jl 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.