mrc-ide / individual

R Package for individual based epidemiological models
https://mrc-ide.github.io/individual
Other
30 stars 16 forks source link

bitset clear method #157

Closed slwu89 closed 3 years ago

slwu89 commented 3 years ago

tiny PR, just implements $clear() for bitsets to zero out all set bits and tests it.

codecov[bot] commented 3 years ago

Codecov Report

Merging #157 (ecb8275) into dev (922dd3b) will increase coverage by 0.03%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #157      +/-   ##
==========================================
+ Coverage   95.92%   95.95%   +0.03%     
==========================================
  Files          26       26              
  Lines        1201     1210       +9     
==========================================
+ Hits         1152     1161       +9     
  Misses         49       49              
Impacted Files Coverage Δ
R/bitset.R 85.71% <100.00%> (+0.60%) :arrow_up:
inst/include/IterableBitset.h 98.52% <100.00%> (+0.03%) :arrow_up:
src/bitset.cpp 98.21% <100.00%> (+0.06%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ffbf7c9...ecb8275. Read the comment docs.

slwu89 commented 3 years ago

@giovannic thanks for looking at this!

I am now entering the temple of small optimizations 🙇‍♂️ I decided to test 3 methods against each other. "for" is the existing for loop, but now assigning 0x0ULL literal to each element of the vector rather than doing &=. "fill" is using std:fill on the bitmap. "alloc" uses the assignment operator with a new vector ctor as your suggested. The results of checking speed are....not what I expected. It looks like the for loop is faster above 1e6 elements.

bset_clear.pdf

giovannic commented 3 years ago

wow, loop go brrr