Closed mmuscarella closed 8 years ago
I identified one issue that I caused because I used node.age in the beginning of the function. I now put it inside an if statement so that it only runs when include.root == TRUE and the tree is rooted.
> microbenchmark(pd(phylocom$sample, phylocom$phylo, include.root = F),
+ pd2(phylocom$sample, phylocom$phylo, include.root = F), times = 3)
Unit: milliseconds
expr min lq mean median
pd(phylocom$sample, phylocom$phylo, include.root = F) 3.912658 3.962499 4.064210 4.012341
pd2(phylocom$sample, phylocom$phylo, include.root = F) 3.669715 3.730180 4.435009 3.790644
uq max neval
4.139987 4.267632 3
4.817657 5.844669 3
>
> microbenchmark(pd(phylocom$sample, phylocom$phylo, include.root = T),
+ pd2(phylocom$sample, phylocom$phylo, include.root = T), times = 3)
Unit: milliseconds
expr min lq mean
pd(phylocom$sample, phylocom$phylo, include.root = T) 10.193854 10.223595 11.001160
pd2(phylocom$sample, phylocom$phylo, include.root = T) 5.891472 5.945265 6.284063
median uq max neval
10.253336 11.404812 12.556289 3
5.999057 6.480358 6.961659 3
I modified the pd function and drastically increased speed. Improvements are based on replacing values in a vector instead of concatenating inside a loop, and I reduced the number of times node.age() was run by putting a global node.age function outside of the loop. Performance increases are shown below: