Created
September 12, 2024 21:52
-
-
Save fo40225/cddf82eb998ff102d2938883edd899df to your computer and use it in GitHub Desktop.
cran bioconductor mirror speed test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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