Skip to content
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

Benchmarks for M/Z sorted Spectrum1 #136

Closed
jorainer opened this issue Jul 27, 2016 · 0 comments
Closed

Benchmarks for M/Z sorted Spectrum1 #136

jorainer opened this issue Jul 27, 2016 · 0 comments
Labels

Comments

@jorainer
Copy link
Collaborator

Wanted to share benchmarks for different approaches to ensure/enforce ordering of M/Z-intensity value pairs by M/Z value in Spectrum1 objects (relates to issue #135):

I compared:

  • Sorting of values in R (after reading the values with mzR and before creating the Spectrum1 objects) using either method = "radix" and method = "shell".
  • Sorting of values in the C constructor for Spectrum1 objects (i.e. sorting values in C).
> suppressWarnings(
+     onDisk <- readMSData2(files = mzf, centroided = TRUE)
+ )
Reading 3670 spectra from file POS_C_O_001.mzML
Reading 3670 spectra from file POS_C_O_002.mzML
> library(microbenchmark)
> fDataPerFile <- split(fData(onDisk), f = fData(onDisk)$fileIdx)
> BPPARAM <- SerialParam()
> ## Without M/Z sorting
> unsorted <- function() {
+         bplapply(fDataPerFile,
+                  FUN = MSnbase:::.applyFun2SpectraOfFileMulti,
+                  filenames = fileNames(onDisk), queue = list(),
+                  APPLYFUN = NULL, BPPARAM = BPPARAM)
+ }
> ## With sorting in R using method = "radix"
> radixSortedR <- function() {
+     bplapply(fDataPerFile,
+              FUN = MSnbase:::.applyFun2SpectraOfFileMultiRadixSortMz,
+              filenames = fileNames(onDisk), queue = list(),
+              APPLYFUN = NULL, BPPARAM = BPPARAM)
+ }
> ## With sorting in R using method = "shell"
> shellSortedR <- function() {
+     bplapply(fDataPerFile,
+              FUN = MSnbase:::.applyFun2SpectraOfFileMultiShellSortMz,
             filenames = fileNames(onDisk), queue = list(),
+ +              APPLYFUN = NULL, BPPARAM = BPPARAM)
+ }
> ## With sorting performed in the C constructor
> constructorSorted <- function() {
+     bplapply(fDataPerFile,
+              FUN = MSnbase:::.applyFun2SpectraOfFileMulti2,
+              filenames = fileNames(onDisk), queue = list(),
+              APPLYFUN = NULL, BPPARAM = BPPARAM)
+ }
>
> ## o Compare unsorted vs radix sorted in R
> microbenchmark(unsorted(), radixSortedR(),times = 10)
Unit: seconds
           expr     min       lq     mean   median        uq       max neval
     unsorted() 5.82697 6.225438 6.769096 6.859658  7.058579  8.187952    10
 radixSortedR() 7.45798 7.800574 8.950423 8.530921 10.016772 11.586625    10
 cld
  a 
   b
> 
> ## o Compare radix sorted in R vs shell sorted in R
> microbenchmark(radixSortedR(), shellSortedR(), times = 10)
Unit: seconds
           expr      min       lq     mean   median       uq       max neval
 radixSortedR() 7.962823 8.044155 8.680846 8.381478 8.951652 10.734356    10
 shellSortedR() 8.145214 8.515322 8.846406 8.711967 9.217153  9.994807    10
 cld
   a
   a
> 
> ## o Compare radix sorted in R vs sorted in C constructor
> microbenchmark(radixSortedR(), constructorSorted(), times = 10)
Unit: seconds
                expr      min       lq     mean   median       uq      max
      radixSortedR() 7.401449 7.435909 7.847040 7.779204 8.147483 8.541478
 constructorSorted() 6.189033 6.503043 6.616889 6.641096 6.725856 7.055754
 neval cld
    10   b
    10  a 

There's no big difference, but still, the implementation in C outperforms all.

jorainer added a commit that referenced this issue Jul 27, 2016
o New Spectrum1_mz_sorted and Spectra1_mz_sorted functions that use
  C-level constructors that enforce ordering of M/Z-intensity pairs by
  M/Z.
o Unit test for new constructors (in test_Spectrum_Constructor.R).
o Cleanup of C-code.
o Benchmarks for comparison of M/Z sorting in R and in the
  C-constructors (see issue #136 for results).
o Add smoothed argument to Spectrum1 constructor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant