Skip to content

Instantly share code, notes, and snippets.

@fo40225
Created September 12, 2024 21:52
Show Gist options
  • Save fo40225/cddf82eb998ff102d2938883edd899df to your computer and use it in GitHub Desktop.
Save fo40225/cddf82eb998ff102d2938883edd899df to your computer and use it in GitHub Desktop.
cran bioconductor mirror speed test
options(timeout = 10)
cranometer <- function(ms = getCRANmirrors(all = FALSE, local.only = FALSE),...){
dest = tempfile()
nms = dim(ms)[1]
ms$t = rep(NA,nms)
for(i in 1:nms){
m = ms[i,]
url = paste(m$URL,"src/base/NEWS",sep="")
t = try(system.time(download.file(url,dest),gcFirst=TRUE))
if(file.exists(dest) && file.info(dest)$size > 0){
ms$t[i] = t['elapsed']
}else{
ms$t[i] = NA
}
if(file.exists(dest)){
file.remove(dest)
}
}
ms$t <- as.numeric(ms$t)
ms <- na.omit(ms)
return(ms)
}
# this can take some time
x <- cranometer()
time_order <- order(x$t)
# a quick overview of the fastest mirrors
head(x[time_order,c(1:4, 9)], 20)
bioconductor_mirror_test <- function(ms = read.csv("https://bioconductor.org/BioC_mirrors.csv"), ...) {
dest = tempfile()
nms = nrow(ms)
ms$t = rep(NA, nms)
for (i in 1:nms) {
m = ms[i, ]
url = paste(m$URL, "packages/release/bioc/index.html", sep = "")
t = try(system.time(download.file(url, dest), gcFirst = TRUE))
if (file.exists(dest) && file.info(dest)$size > 0) {
ms$t[i] = t['elapsed']
} else {
ms$t[i] = NA
}
if (file.exists(dest)) {
file.remove(dest)
}
}
ms$t <- as.numeric(ms$t)
ms <- na.omit(ms)
return(ms)
}
results <- bioconductor_mirror_test()
time_order <- order(results$t)
# a quick overview of the fastest mirrors
head(results[time_order,c(1:4, 9)], 20)
#chooseCRANmirror()
#chooseBioCmirror()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment