Skip to content

Commit

Permalink
Following CRAN advices use microbenchmark conditionnally
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekyt committed May 5, 2017
1 parent fe7dc8f commit 53716d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Corrected bug so that dense matrices can be transformed to stack data frame using ` matrix_to_stack()` (#19),
* Updated citation for Violle et al. 2017,
* Use package [`goodpractice`](https://github.com/MangoTheCat/goodpractice) to enforce better code style,
* Add `is_relative()` function to test if matrix contains relative abundances, `scarcity()` and `distinctiveness()` now warns if it is not the case (#21).
* Add `is_relative()` function to test if matrix contains relative abundances, `scarcity()` and `distinctiveness()` now warns if it is not the case (#21),
* Conditionnally use [`microbenchmark`](https://cran.r-project.org/package=microbenchmark) following CRAN advices.


# funrar 1.0.2
Expand Down
40 changes: 22 additions & 18 deletions vignettes/sparse_matrices.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ sparse matrices reduce the amount of RAM necessary to store them. The more zeros

## Benchmark

We can now compare the performances of the algorithms in rarity indices computation between a sparse matrix and a regular one, using the popular `microbenchmark` R package:
We can now compare the performances of the algorithms in rarity indices computation between a sparse matrix and a regular one, using the popular [`microbenchmark`](https://cran.r-project.org/package=microbenchmark) R package:

```{r microBenchDist}
library(microbenchmark)
library(funrar)
# Get a table of traits
Expand All @@ -97,8 +96,11 @@ rownames(trait_df) = paste0("sp", 1:ncol(my_mat))
# Compute distance matrix
dist_mat = compute_dist_matrix(trait_df)
microbenchmark(regular = distinctiveness(my_mat, dist_mat),
sparse = distinctiveness(sparse_mat, dist_mat))
if (requireNamespace("microbenchmark", quietly = TRUE)) {
microbenchmark::microbenchmark(
regular = distinctiveness(my_mat, dist_mat),
sparse = distinctiveness(sparse_mat, dist_mat))
}
```


Expand Down Expand Up @@ -138,19 +140,21 @@ mat_filling(all_mats$`99`$mat)
Now we can compare the speed of the algorithms:

```{r, eval=FALSE}
mat_bench = microbenchmark(
mat_0 = distinctiveness(all_mats$`0`$mat, dist_mat),
sparse_0 = distinctiveness(all_mats$`0`$sparse, dist_mat),
mat_1 = distinctiveness(all_mats$`1`$mat, dist_mat),
sparse_1 = distinctiveness(all_mats$`1`$sparse, dist_mat),
mat_2 = distinctiveness(all_mats$`2`$mat, dist_mat),
sparse_2 = distinctiveness(all_mats$`2`$sparse, dist_mat),
mat_49 = distinctiveness(all_mats$`49`$mat, dist_mat),
sparse_49 = distinctiveness(all_mats$`49`$sparse, dist_mat),
mat_99 = distinctiveness(all_mats$`99`$mat, dist_mat),
sparse_99 = distinctiveness(all_mats$`99`$sparse, dist_mat),
times = 5)
autoplot(mat_bench)
if (requireNamespace("microbenchmark", quietly = TRUE)) {
mat_bench = microbenchmark::microbenchmark(
mat_0 = distinctiveness(all_mats$`0`$mat, dist_mat),
sparse_0 = distinctiveness(all_mats$`0`$sparse, dist_mat),
mat_1 = distinctiveness(all_mats$`1`$mat, dist_mat),
sparse_1 = distinctiveness(all_mats$`1`$sparse, dist_mat),
mat_2 = distinctiveness(all_mats$`2`$mat, dist_mat),
sparse_2 = distinctiveness(all_mats$`2`$sparse, dist_mat),
mat_49 = distinctiveness(all_mats$`49`$mat, dist_mat),
sparse_49 = distinctiveness(all_mats$`49`$sparse, dist_mat),
mat_99 = distinctiveness(all_mats$`99`$mat, dist_mat),
sparse_99 = distinctiveness(all_mats$`99`$sparse, dist_mat),
times = 5)
autoplot(mat_bench)
}
```

0 comments on commit 53716d2

Please sign in to comment.