-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring test: Simple loop for prepare_spectra()
assignments
#56
Conversation
Current main branch: r$> # Set up -----------------------------------------------------------------------
library("opusreader2")
r$> path <- file.path("data", "spectra", "2018-NABO")
opus_files <- list.files(
path = path, pattern = "\\.\\d+$", full.names = TRUE, recursive = TRUE
)
# number of OPUS files
length(opus_files)
[1] 1612
r$> bnch_seq <- bench::mark(
data <- opusreader2::read_opus(dsn = path)
)
Warning message:
Some expressions had a GC in every iteration; so filtering is disabled.
r$> bnch_seq
# A tibble: 1 × 13
expression min median itr/s…¹ mem_a…² gc/se…³ n_itr n_gc total…⁴
<bch:expr> <bch:tm> <bch:t> <dbl> <bch:b> <dbl> <int> <dbl> <bch:t>
1 data <- opusreader2::read_opus(dsn = path) 20.9s 20.9s 0.0478 8.32GB 5.02 1 105 20.9s
# … with 4 more variables: result <list>, memory <list>, time <list>, gc <list>, and abbreviated
# variable names ¹`itr/sec`, ²mem_alloc, ³`gc/sec`, ⁴total_time
# ℹ Use `colnames()` to see all variable names Current branch r$> remotes::install_github("spectral-cockpit/opusreader2", ref = "opt-52-prepare-spectra-loop")
...
r$> library("opusreader2")
library("bench")
path <- file.path("data", "spectra", "2018-NABO")
opus_files <- list.files(
path = path, pattern = "\\.\\d+$", full.names = TRUE, recursive = TRUE
)
r$> bnch_seq <- bench::mark(
data <- opusreader2::read_opus(dsn = path)
)
Warning message:
Some expressions had a GC in every iteration; so filtering is disabled.
r$> bnch_seq
# A tibble: 1 × 13
expression min median itr/s…¹ mem_a…² gc/se…³ n_itr n_gc total…⁴
<bch:expr> <bch:tm> <bch:t> <dbl> <bch:b> <dbl> <int> <dbl> <bch:t>
1 data <- opusreader2::read_opus(dsn = path) 20.8s 20.8s 0.0480 8.31GB 5.86 1 122 20.8s
# … with 4 more variables: result <list>, memory <list>, time <list>, gc <list>, and abbreviated
# variable names ¹`itr/sec`, ²mem_alloc, ³`gc/sec`, ⁴total_time
# ℹ Use `colnames()` to see all variable names |
prepare_spectra()
prepare_spectra()
assignments
Take home:
|
i just don't like for-loops 😜. |
There is indeed no difference in time and memory, I am sure opusreader2/R/prepare_spectra.R Line 7 in c3e4c2d
and we can directly assign by element name here opusreader2/R/prepare_spectra.R Line 32 in c3e4c2d
|
There is indeed no difference in time and memory, I am sure |
instead of
Reduce
. @ThomasKnecht I did a bit of refactoring. TheReduce
approach you introduced leads to very elegant, functional code inparse_opus()
. The nested loop on the other hand makes it possible to simplify the code inprepare_spectra()
, and makes the assignment logic very clear in the loop. There is sure pros and cons with each of the approaches. Let me do a benchmark on more files to read, and then let's discuss. Curious about your opinion.