Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Dylan Hocking committed Sep 20, 2024
1 parent 543402c commit 8762cc0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
42 changes: 10 additions & 32 deletions man/atime.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,25 @@ result=FALSE, ...)}
\examples{

## Example 1: polynomial and exponential time string functions.
string.result <- atime::atime(
atime_result_string <- atime::atime(
seconds.limit=0.001,
N=unique(as.integer(10^seq(0,3.5,l=100))),
setup={
subject <- paste(rep("a", N), collapse="")
pattern <- paste(rep(c("a?", "a"), each=N), collapse="")
linear_size_replacement <- paste(rep("REPLACEMENT", N), collapse="")
},
seconds.limit=0.001,
PCRE.match=regexpr(pattern, subject, perl=TRUE),
TRE.match=regexpr(pattern, subject, perl=FALSE),
constant.replacement=gsub("a","constant size replacement",subject),
linear.replacement=gsub("a",subject,subject))
plot(string.result)
linear.replacement=gsub("a",linear_size_replacement,subject))
plot(atime_result_string)

## Example 2: split data table vs frame, constant factor difference.
library(data.table)
split.result <- atime::atime(
setup={
set.seed(1)
DT <- data.table(
x1 = rep(c("c","d"), l=N),
x2 = rep(c("x","y"), l=N),
x3 = rep(c("a","b"), l=N),
y = rnorm(N)
)[sample(.N)]
DF <- as.data.frame(DT)
},
## Example 2: combine using rbind inside or outside for loop.
atime_result_rbind <- atime::atime(
seconds.limit=0.001,
frame=split(DF[names(DF) != "x1"], DF["x1"], drop = TRUE),
table=split(DT, by = "x1", keep.by = FALSE, drop = TRUE)
)
plot(split.result)

## Example 3: combine inside or outside for loop.
atime.list <- atime::atime(
N=as.integer(10^seq(0, 5), by=0.25),
setup={
Nrow <- 1e3
DF <- data.frame(
x1 = rep(c("c","d"), l=Nrow),
x2 = rep(c("x","y"), l=Nrow),
x3 = rep(c("a","b"), l=Nrow))
DF <- data.frame(i=1:100)
},
inside={
big.frame <- data.frame()
Expand All @@ -89,9 +67,9 @@ atime.list <- atime::atime(
for(table.i in 1:N){
big.frame.list[[table.i]] <- DF
}
do.call(rbind, big.frame.list)
big.frame <- do.call(rbind, big.frame.list)
}
)
plot(atime.list)
plot(atime_result_rbind)

}
46 changes: 37 additions & 9 deletions man/references_best.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,54 @@ references_best(L, fun.list=NULL)
\examples{

## Example 1: polynomial and exponential time string functions.
string.result <- atime::atime(
atime_result_string <- atime::atime(
seconds.limit=0.001,
N=unique(as.integer(10^seq(0,4,l=100))),
setup={
subject <- paste(rep("a", N), collapse="")
pattern <- paste(rep(c("a?", "a"), each=N), collapse="")
linear_size_replacement <- paste(rep("REPLACEMENT", N), collapse="")
},
seconds.limit=0.001,
PCRE.match=regexpr(pattern, subject, perl=TRUE),
TRE.match=regexpr(pattern, subject, perl=FALSE),
constant.replacement=gsub("a","constant size replacement",subject),
linear.replacement=gsub("a",subject,subject))
(string.best <- atime::references_best(string.result))
linear.replacement=gsub("a",linear_size_replacement,subject))
(refs_best_string <- atime::references_best(atime_result_string))
## plot method shows each expr and unit in a separate panel.
## default is to show closest larger and smaller references.
plot(string.best)
plot(refs_best_string)
## modifying plot.references changes violet references shown by plot.
string.best$plot.references <- string.best$ref[c("N","N^2","N^3","2^N"),on="fun.name"]
plot(string.best)
refs_best_string$plot.references <- refs_best_string$ref[c("N","N^2","N^3","2^N"),on="fun.name"]
plot(refs_best_string)
## predict method computes N for given units (default seconds limit).
string.pred = predict(string.best)
plot(string.pred)
(pred_string <- predict(refs_best_string))
plot(pred_string)

## Example 2: combine using rbind inside or outside for loop.
atime_result_rbind <- atime::atime(
seconds.limit=0.001,
setup={
DF <- data.frame(i=1:100)
},
inside={
big.frame <- data.frame()
for(table.i in 1:N){
big.frame <- rbind(big.frame, DF)
}
},
outside={
big.frame.list <- list()
for(table.i in 1:N){
big.frame.list[[table.i]] <- DF
}
big.frame <- do.call(rbind, big.frame.list)
}
)
(refs_best_rbind <- atime::references_best(atime_result_rbind))
plot(refs_best_rbind)
refs_best_rbind$plot.references <- refs_best_rbind$ref[c("N","N^2"),on="fun.name"]
plot(refs_best_rbind)
(pred_rbind <- predict(refs_best_rbind))
plot(pred_rbind)

}

0 comments on commit 8762cc0

Please sign in to comment.