cossio / RestrictedBoltzmannMachines.jl

Train and sample Restricted Boltzmann machines in Julia
MIT License
14 stars 3 forks source link

BitArray are slow #6

Closed cossio closed 1 year ago

cossio commented 2 years ago
julia> @benchmark convert(Array{Float32}, b) setup=(b=Array(bitrand(28,28,128));)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  30.867 μs … 591.739 μs  ┊ GC (min … max): 0.00% … 74.02%
 Time  (median):     35.097 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   38.258 μs ±  31.908 μs  ┊ GC (mean ± σ):  5.89% ±  6.67%

        ▄██▇▅▄▅▄▂▁                                              
  ▂▁▂▃▃▇██████████▇▅▄▃▃▃▃▃▃▃▂▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  30.9 μs         Histogram: frequency by time         53.9 μs <

 Memory estimate: 392.06 KiB, allocs estimate: 2.
julia> @benchmark convert(Array{Float32}, b) setup=(b=bitrand(28,28,128);)
BenchmarkTools.Trial: 8586 samples with 1 evaluation.
 Range (min … max):  515.307 μs …  1.291 ms  ┊ GC (min … max): 0.00% … 40.74%
 Time  (median):     556.879 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   576.900 μs ± 66.623 μs  ┊ GC (mean ± σ):  0.63% ±  3.89%

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

 Memory estimate: 392.06 KiB, allocs estimate: 2.
julia> @benchmark Float32.(b) setup=(b=bitrand(28,28,128);)
BenchmarkTools.Trial: 6760 samples with 1 evaluation.
 Range (min … max):  671.621 μs …  1.171 ms  ┊ GC (min … max): 0.00% … 25.08%
 Time  (median):     729.683 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   732.210 μs ± 38.635 μs  ┊ GC (mean ± σ):  0.35% ±  2.67%

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

 Memory estimate: 392.06 KiB, allocs estimate: 2.
julia> @benchmark Float32.(b) setup=(b=Array(bitrand(28,28,128));)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  104.868 μs … 715.391 μs  ┊ GC (min … max): 0.00% … 62.31%
 Time  (median):     109.923 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   116.574 μs ±  37.904 μs  ┊ GC (mean ± σ):  2.04% ±  5.74%

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

 Memory estimate: 392.06 KiB, allocs estimate: 2.
cossio commented 1 year ago

Now we are converting to Float by default