library(tinycodet)
library(ggplot2)
loadNamespace("bench")
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "\\d"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
locate_stringi <- function(...) {
stringi::stri_locate_all(...)
stringi::stri_count(...)
}
bm.stri_locate_ith_vs_all <- bench::mark(
"stri_locate_ith" = stri_locate_ith_regex(x, p, i),
"stringi::stri_locate_all" = stringi::stri_locate_all(x, regex = p),
min_iterations = 500,
check = FALSE,
filter_gc = FALSE
)
summary(bm.stri_locate_ith_vs_all)
autoplot(bm.stri_locate_ith_vs_all)
save(bm.stri_locate_ith, file = "bm.stri_locate_ith_vs_all.RData")
setwd("D:/D Desktop/Publications/R package tinycodet/tinycodet/vignettes/articles")
save(bm.stri_locate_ith_vs_all, file = "bm.stri_locate_ith_vs_all.RData")
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "1"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
locate_stringi <- function(...) {
stringi::stri_locate_all(...)
stringi::stri_count(...)
}
bm.stri_locate_ith_vs_all <- bench::mark(
"stri_locate_ith" = stri_locate_ith_fixed(x, p, i),
"stringi::stri_locate_all" = stringi::stri_locate_all(x, fixed = p),
min_iterations = 500,
check = FALSE,
filter_gc = FALSE
)
summary(bm.stri_locate_ith_vs_all)
autoplot(bm.stri_locate_ith_vs_all)
install.packages("strex")
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "\\d"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "\\d"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
bm.stri_locate_ith_vs_strex <- bench::mark(
"stri_locate_ith" = stri_locate_ith_regex(x, p, i),
"strex::str_locate_nth" = strex::str_locate_nth(x, p, i),
min_iterations = 500,
check = FALSE,
filter_gc = FALSE
)
summary(bm.stri_locate_ith_vs_strex)
autoplot(bm.stri_locate_ith_vs_strex)
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "1"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
setwd("D:/D Desktop/Publications/R package tinycodet/tinycodet/vignettes/articles")
bm.stri_locate_ith_vs_strex <- bench::mark(
"stri_locate_ith" = stri_locate_ith_fixed(x, p, i),
"strex::str_locate_nth" = strex::str_locate_nth(x, stringr::fixed(p), i),
min_iterations = 500,
check = FALSE,
filter_gc = FALSE
)
library(tinycodet)
library(ggplot2)
loadNamespace("bench")
n <- 5e4
x <- rep(paste0(1:50, collapse = ""), n)
p <- "1"
i <- sample(c(-50:-1, 1:50), replace=TRUE, size = n)
bm.stri_locate_ith_vs_strex <- bench::mark(
"stri_locate_ith" = stri_locate_ith_fixed(x, p, i),
"strex::str_locate_nth" = strex::str_locate_nth(x, stringr::fixed(p), i),
min_iterations = 500,
check = FALSE,
filter_gc = FALSE
)
summary(bm.stri_locate_ith_vs_strex)
autoplot(bm.stri_locate_ith_vs_strex)
setwd("D:/D Desktop/Publications/R package tinycodet/tinycodet/vignettes/articles")
save(bm.stri_locate_ith_vs_strex, file = "bm.stri_locate_ith_vs_strex.RData")
setwd("D:/D Desktop/Publications/R package tinycodet/tinycodet/vignettes/articles")
load("bm.stri_locate_ith_vs_all.RData")
ggplot2::autoplot(bm.stri_locate_ith_vs_all)
summary(bm.stri_locate_ith_vs_all)
load("bm.stri_locate_ith_vs_strex.RData")
ggplot2::autoplot(bm.stri_locate_ith_vs_strex)
body <- "
IntegerVector rcpp_convert_i0(SEXP n_matches, SEXP i) {
int n = length(i);
const int *pm = INTEGER(n_matches);
const int *pi = INTEGER(i);
int *pout;
SEXP out = PROTECT(allocVector(INTSXP, n));
for(int j = 0; j < n; ++j) {
if(pi[j] == R_NaInt) {
stop(\"`i` is not allowed to be zero or NA\");
}
else if(pi[j] < 0) {
res = pm[j] - abs(pi[j] + 1);
if(res < 1) {
pout[j] = 1;
} else {
pout[j] = res;
}
}
else if(pi[j] > 0) {
if(pi[j] < pm[j]) {
pout[j] = pi[j];
} else {
pout[j] = pm[j];
}
}
else {
stop(\"`i` is not allowed to be zero or NA\");
}
}
UNPROTECT(1);
return out;
}
"
body <- "
int n = length(i);
const int *pm = INTEGER(n_matches);
const int *pi = INTEGER(i);
int *pout;
SEXP out = PROTECT(allocVector(INTSXP, n));
for(int j = 0; j < n; ++j) {
if(pi[j] == R_NaInt) {
stop(\"`i` is not allowed to be zero or NA\");
}
else if(pi[j] < 0) {
res = pm[j] - abs(pi[j] + 1);
if(res < 1) {
pout[j] = 1;
} else {
pout[j] = res;
}
}
else if(pi[j] > 0) {
if(pi[j] < pm[j]) {
pout[j] = pi[j];
} else {
pout[j] = pm[j];
}
}
else {
stop(\"`i` is not allowed to be zero or NA\");
}
}
UNPROTECT(1);
return out;
"
C_convert_i0 <- inline::cfunction(
signature(n_matches = "SEXP", i = "SEXP"), body = body
)
body <- "
int n = length(i);
const int *pm = INTEGER(n_matches);
const int *pi = INTEGER(i);
int *pout;
SEXP out = PROTECT(allocVector(INTSXP, n));
pout = INTEGER(out);
for(int j = 0; j < n; ++j) {
if(pi[j] == R_NaInt) {
stop(\"`i` is not allowed to be zero or NA\");
}
else if(pi[j] < 0) {
res = pm[j] - abs(pi[j] + 1);
if(res < 1) {
pout[j] = 1;
} else {
pout[j] = res;
}
}
else if(pi[j] > 0) {
if(pi[j] < pm[j]) {
pout[j] = pi[j];
} else {
pout[j] = pm[j];
}
}
else {
stop(\"`i` is not allowed to be zero or NA\");
}
}
UNPROTECT(1);
return out;
"
C_convert_i0 <- inline::cfunction(
signature(n_matches = "SEXP", i = "SEXP"), body = body
)
body <- "
int n = length(i);
const int *pm = INTEGER(n_matches);
const int *pi = INTEGER(i);
int *pout;
SEXP out = PROTECT(allocVector(INTSXP, n));
pout = INTEGER(out);
for(int j = 0; j < n; ++j) {
if(pi[j] == R_NaInt) {
error(\"`i` is not allowed to be zero or NA\");
}
else if(pi[j] < 0) {
res = pm[j] - abs(pi[j] + 1);
if(res < 1) {
pout[j] = 1;
} else {
pout[j] = res;
}
}
else if(pi[j] > 0) {
if(pi[j] < pm[j]) {
pout[j] = pi[j];
} else {
pout[j] = pm[j];
}
}
else {
error(\"`i` is not allowed to be zero or NA\");
}
}
UNPROTECT(1);
return out;
"
C_convert_i0 <- inline::cfunction(
signature(n_matches = "SEXP", i = "SEXP"), body = body
)
body <- "
int n = length(i);
const int *pm = INTEGER(n_matches);
const int *pi = INTEGER(i);
int *pout;
int res = 0;
SEXP out = PROTECT(allocVector(INTSXP, n));
pout = INTEGER(out);
for(int j = 0; j < n; ++j) {
if(pi[j] == R_NaInt) {
error(\"`i` is not allowed to be zero or NA\");
}
else if(pi[j] < 0) {
res = pm[j] - abs(pi[j] + 1);
if(res < 1) {
pout[j] = 1;
} else {
pout[j] = res;
}
}
else if(pi[j] > 0) {
if(pi[j] < pm[j]) {
pout[j] = pi[j];
} else {
pout[j] = pm[j];
}
}
else {
error(\"`i` is not allowed to be zero or NA\");
}
}
UNPROTECT(1);
return out;
"
C_convert_i0 <- inline::cfunction(
signature(n_matches = "SEXP", i = "SEXP"), body = body
)
i <- sample(-50:50, 5e5, TRUE)
n.matches <- sample(0:50, 5e5, TRUE)
foo <- bench::mark(
C = C_convert_i0(n.matches, i),
rcpp = tinycodet:::.rcpp_convert_i0(n.matches, i),
min_iterations = 500
)
i <- sample(1:50, 5e5, TRUE)
n.matches <- sample(0:50, 5e5, TRUE)
foo <- bench::mark(
C = C_convert_i0(n.matches, i),
rcpp = tinycodet:::.rcpp_convert_i0(n.matches, i),
min_iterations = 500
)
summary(foo)
ggplot2::autoplot(foo)
ggplot2::autoplot(bm.stri_locate_ith_vs_all)
x <- "cty"
y <- "sqrt(hwy)"
color <- "drv"
ggplot2::ggplot(d, aes(x, y, color = color)) +
ggplot2::geom_point()
ggplot2::mpg
data("mpg", package = "ggplot2")
data("mpg", package = "ggplot2")
x <- "cty"
y <- "sqrt(hwy)"
color <- "drv"
ggplot2::ggplot(mpg, aes(x, y, color = color)) +
ggplot2::geom_point()
ggplot2::ggplot(mpg, ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point()
ggplot2::ggplot(data.frame(1), ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point()
ggplot2::ggplot(mpg, ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point()
data("mpg", package = "ggplot2")
x <- "cty"
y <- "hwy"
color <- "drv"
ggplot2::ggplot(mpg, ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point()
data("mpg", package = "ggplot2")
x <- "cty"
y <- "hwy"
z <- "drv"
ggplot2::ggplot(mpg, ggplot2::aes(x, y, color = z)) +
ggplot2::geom_point()
?tinycodet
?tinycodet::`tinycodet-package`
