# NOT RUN {
## Generate some random data
set.seed(28)
mySamp <- sample(10^6, 5*10^5)
## Quickly generate prime factorizations up
## to 10^6 (max element from mySamp)
system.time(allPFacs <- primeFactorizationList(10^6))
## Use generated prime factorization for further
## analysis by accessing the index of allPFacs
for (s in mySamp) {
pFac <- allPFacs[[s]]
## Continue algorithm
}
## Generating the prime factorization on the fly is much
## slower despite 1. gmp::factorize being one of the fastest
## stand alone factoring algorithms and 2. there are fewer
## factorizations being performed (allPFacs above contains
## 10^6 factorizations and the below only generates the
## factorizations of the numbers in mySamp (5*10^5 elements)).
# }
# NOT RUN {
system.time(mySampPFacs <- lapply(mySamp, gmp::factorize))
# }
Run the code above in your browser using DataLab