Created
March 31, 2016 10:25
-
-
Save symbolrush/14716283f96d0c143e60d5a67f8f19c7 to your computer and use it in GitHub Desktop.
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
set.seed(1) | |
vec <- runif(1000) | |
vec1 <- vec | |
print(paste0("Die beiden Vektoren sind identisch: ", all.equal(vec, vec1))) | |
print(paste0("Die Variante for-loop dauert: ", summary(microbenchmark::microbenchmark( | |
for (i in 1:length(vec)) { | |
if (vec[i] > 0.5) {vec[i] <- 10} | |
} | |
), unit = "ms")$uq, "ms")) | |
print(paste0("Die Variante ifelse dauert: ", summary(microbenchmark::microbenchmark( | |
vec1 <- ifelse(vec1 > 0.5, 10, vec1) | |
), unit = "ms")$uq, "ms")) | |
print(paste0("Die beiden Vektoren sind auch nach der Operation identisch: ", all.equal(vec, vec1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment