spectral-cockpit / opusreader2

Read OPUS binary files from Fourier-Transform Infrared (FT-IR) spectrometers of the company Bruker Optics GmbH & Co. in base R
https://spectral-cockpit.github.io/opusreader2/
MIT License
18 stars 2 forks source link

🏄 `prepare_spectra()`: Improving speed while maintaining reasonable memory consumption #55

Closed philipp-baumann closed 1 year ago

philipp-baumann commented 1 year ago

addresses part of #52

philipp-baumann commented 1 year ago

My conclusion is that at least in Reduce context, append() instead of c() is neither faster nor better in terms of memory (needs also more frequent calls to Garbage Collector.

before (current master) : c3e4c2d38594574f38de48283e6e181ddfda8dfb

r$> library("opusreader2")
    file <- opus_file()

r$> bnch <- bench::mark(
      data <- read_opus(dsn = file)
    )

r$> bnch
# A tibble: 1 × 13
  expression                         min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result            memory               time            gc               
  <bch:expr>                    <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list>            <list>               <list>          <list>           
1 data <- read_opus(dsn = file)   17.5ms   17.9ms      54.4    1.73MB     172.     6    19      110ms <named list [20]> <Rprofmem [504 × 3]> <bench_tm [25]> <tibble [25 × 3]>

after (this PR)

r$> library("opusreader2")
    file <- opus_file()

r$> bnch <- bench::mark(
      data <- read_opus(dsn = file)
    )
Warning message:
Some expressions had a GC in every iteration; so filtering is disabled. 

r$> bnch
# A tibble: 1 × 13
  expression                         min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result            memory               time            gc               
  <bch:expr>                    <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list>            <list>               <list>          <list>           
1 data <- read_opus(dsn = file)   19.4ms     20ms      46.7    2.07MB     52.6    24    27      514ms <named list [20]> <Rprofmem [577 × 3]> <bench_tm [24]> <tibble [24 × 3]>
philipp-baumann commented 1 year ago

closing because this PR with append has no advantages.