Skip to content

Instantly share code, notes, and snippets.

@sckott
Created August 28, 2012 19:09
Show Gist options
  • Save sckott/3502640 to your computer and use it in GitHub Desktop.
Save sckott/3502640 to your computer and use it in GitHub Desktop.
speed of random matrix algorithms
mm <- matrix(0, 10, 5)
m <- 10
n <- 5
> system.time( replicate(1000, apply(mm, c(1,2), function(x) sample(c(0,1),1)) ) ) # @recology_
user system elapsed
0.414 0.015 0.429
> system.time( replicate(1000, matrix(rbinom(10*5,1,.5),ncol=5,nrow=10) ) ) # @distribecology
user system elapsed
0.012 0.000 0.012
> system.time( replicate(1000, matrix(sample(0:1, m*n, replace=TRUE),m,n) ) ) # @revodavid & @hylospar
user system elapsed
0.013 0.000 0.012
> system.time( replicate(1000, round(matrix(runif(m*n), m, n)), ) ) # @zentree
user system elapsed
0.013 0.000 0.013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment