Created
March 8, 2016 02:41
-
-
Save brodieG/6f92827213388d54fb67 to your computer and use it in GitHub Desktop.
Demonstrate Some Optimizations to Crayon Substring
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
## Lightly edited for clarity | |
R version 3.2.2 (2015-08-14) -- "Fire Safety" | |
> install.packages("crayon") | |
trying URL 'http://cran.r-project.org/bin/macosx/mavericks/contrib/3.2/crayon_1.3.1.tgz' | |
Content type 'application/x-gzip' length 604079 bytes (589 KB) | |
================================================== | |
downloaded 589 KB | |
> x <- capture.output(matrix(runif(1000), ncol=10)) | |
> library(microbenchmark) | |
> library(crayon) | |
> microbenchmark(substr(x, 1, 20), col_substr(x, 1, 20), times=10) | |
Unit: microseconds | |
expr min lq mean median uq | |
substr(x, 1, 20) 35.568 35.952 37.161 37.699 37.853 | |
col_substr(x, 1, 20) 121841.904 123384.504 128270.798 123884.187 128922.810 | |
max neval | |
39.213 10 | |
159359.228 10 | |
> remove.packages("crayon") | |
Removing package from ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’ | |
(as ‘lib’ is unspecified) | |
> q() | |
Save workspace image? [y/n/c]: y | |
[Previously saved workspace restored] | |
> devtools::install() | |
Installing crayon | |
* DONE (crayon) | |
> library(crayon) | |
> library(microbenchmark) | |
> microbenchmark(substr(x, 1, 20), col_substr(x, 1, 20), times=10) | |
Unit: microseconds | |
expr min lq mean median uq | |
substr(x, 1, 20) 35.412 35.787 41.5175 37.1525 39.909 | |
col_substr(x, 1, 20) 19951.044 21544.627 22157.1421 21905.3320 22659.350 | |
max neval | |
78.953 10 | |
25438.851 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment