Created
July 5, 2012 23:01
-
-
Save sckott/3056983 to your computer and use it in GitHub Desktop.
getURL vs. GET
This file contains hidden or 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
library(httr); library(plyr); require(RCurl) | |
stackexchange_GET <- function(ids, url = "https://api.stackexchange.com/2.0/users/") | |
{ | |
res <- GET(paste0(url, ids), query = list(site = "stackoverflow")) | |
json <- parsed_content(res) | |
json | |
} | |
stackexchange_getURL <- function(ids, url = "https://api.stackexchange.com/2.0/users/") | |
{ | |
url2 <- paste(url, ids, "?site=stackoverflow", sep="") | |
res <- getURL(url2, .opts=list(encoding="identity,gzip")) | |
fromJSON(res)[[1]] | |
} | |
# GET does fine | |
system.time( stackexchange_GET(ids = "16632") ) | |
system.time( stackexchange_getURL(ids = "16632") ) | |
# GET much slower with many ids passed in to the function | |
system.time( replicate(3, llply(list(16632, 258662, 1097181, 1033896, 1207152, 1207153, 1207154, 1207155, 1207156), function(x) stackexchange_GET(ids=x))) ) | |
system.time( replicate(3, stackexchange_getURL(ids = "16632;258662;1097181;1033896;1207152;1207153;1207154;1207155;1207156")) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment