Displaying 20 results from an estimated 303 matches for "microbenchmark".
Did you mean:
microbenchmarks
2013 Jul 02
2
cache most-recent dispatch
...very helpful in loops.
fun0 <- function(x)
sapply(x, paste, collapse="+")
fun1 <- function(x) {
paste <- selectMethod(paste, class(x[[1]]))
sapply(x, paste, collapse="+")
}
lst <- split(rep(LETTERS, 100), rep(1:1300, 2))
library(microbenchmark)
microbenchmark(fun0(lst), times=10)
## Unit: milliseconds
## expr min lq median uq max neval
## fun0(lst) 4.153287 4.180659 4.513539 5.19261 5.280481 10
setGeneric("paste")
microbenchmark(fun0(lst), fun1(lst), times=10)
## > m...
2017 Aug 22
4
How to benchmark speed of load/readRDS correctly
...R and tried several ways to test if load(file.Rdata) or readRDS(file.rds) is faster. The files file.Rdata and file.rds contain the same data, the first created with save(d, ' file.Rdata', compress=F) and the second with saveRDS(d, ' file.rds', compress=F).
First I used the function microbenchmark() and was a astonished about the max value of the output.
FIRST TEST:
> library(microbenchmark)
> microbenchmark(
+ n <- readRDS('file.rds'),
+ load('file.Rdata')
+ )
Unit: milliseconds
expr min lq...
2012 Mar 17
2
Coalesce function in BBmisc, emoa, and microbenchmark packages
Hello All,
Need to coalesce some columns using R. Looked online to see how this is done. One approach appears to be to use ifelse. Also uncovered a coalesce function in the BBmisc, emoa, and microbenchmark packages.
Trouble is I can't seem to get it to work in any of these packages. Or perhaps I misunderstand what it's intended to do. The documentation is generally pretty scant.
Working with two columns: Date of Death (DOD) and Last Known Date Alive (LKDA). One or the other column is popula...
2017 Nov 20
2
Small performance bug in [.Date
Hi all,
I think there's an unnecessary line in [.Date which has a considerable
impact on performance when subsetting large dates:
x <- Sys.Date() + 1:1e6
microbenchmark::microbenchmark(x[1])
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> x[1] 920.651 1039.346 3624.833 2294.404 3786.881 41176.38 100
`[.Date` <- function(x, ..., drop = TRUE) {
cl <- oldClass(x)
# class(x) <- NULL
val <...
2018 Mar 13
2
Possible Improvement to sapply
FYI, in R devel (to become 3.5.0), there's isFALSE() which will cut
some corners compared to identical():
> microbenchmark::microbenchmark(identical(FALSE, FALSE), isFALSE(FALSE))
Unit: nanoseconds
expr min lq mean median uq max neval
identical(FALSE, FALSE) 984 1138 1694.13 1218.0 1337.5 13584 100
isFALSE(FALSE) 713 761 1133.53 809.5 871.5 18619 100
> microbenchmark...
2011 Aug 23
2
Increase transparency: suggestion on how to avoid namespaces and/or unnecessary overwrites of existing functions
...' is overwritten:
parse(text="a <- 5") # Works
require(R.utils)
require(roxygen)
parse(text="a <- 5") # Does not work anymore
################# START A NEW R SESSION BEFORE YOU CONTINUE
####################
# Inefficiency of 'namespace::fun()':
require(microbenchmark)
res.a <- microbenchmark(eval(parse(text="a <- 5")))
res.b <- microbenchmark(eval(base::parse(text="a <- 5")))
median(res.a$time)/median(res.b$time)
# Can be made up by explicit assignment:
foo <- base::parse
res.a <- microbenchmark(eval(parse(text="a <...
2017 Aug 22
0
How to benchmark speed of load/readRDS correctly
The large value for maximum time may be due to garbage collection, which
happens periodically. E.g., try the following, where the
unlist(as.list()) creates a lot of garbage. I get a very large time every
102 or 51 iterations and a moderately large time more often
mb <- microbenchmark::microbenchmark({ x <- as.list(sin(1:5e5)); x <-
unlist(x) / cos(1:5e5) ; sum(x) }, times=1000)
plot(mb$time)
quantile(mb$time * 1e-6, c(0, .5, .75, .90, .95, .99, 1))
# 0% 50% 75% 90% 95% 99% 100%
# 59.04446 82.15453 102.17522 180.36986 187.52667 233...
2017 Aug 22
1
How to benchmark speed of load/readRDS correctly
Note that if you force a garbage collection each iteration the times are
more stable. However, on the average it is faster to let the garbage
collector decide when to leap into action.
mb_gc <- microbenchmark::microbenchmark(gc(), { x <- as.list(sin(1:5e5)); x
<- unlist(x) / cos(1:5e5) ; sum(x) }, times=1000,
control=list(order="inorder"))
with(mb_gc, plot(time[expr!="gc()"]))
with(mb_gc, quantile(1e-6*time[expr!="gc()"], c(0, .5, .75, .9, .95, .99,
1)))
# 0%...
2015 Nov 17
2
[RFC] A new intrinsic, `llvm.blackbox`, to explicitly prevent constprop, die, etc optimizations
...wrote:
> > You don't appear to have addressed my suggestion to not require a perfect
> > external world, instead to measure the overhead of an imperfect world (by
> > using an empty benchmark) and subtracting that from the measured
> benchmark
> > score.
>
> In microbenchmarks, performance is not additive. You can't compose
> two pieces of code and predict that the benchmark results will be the
> sum of the individual measurements.
>
This sounds like an argument against microbenchmarks in general, rather
than against James's point. James' point as...
2018 Feb 11
4
Parallel assignments and goto
...if (n <= 1)
return(acc)
else {
rlang::env_bind(.tailr_env, n = n - 1, acc = acc * n)
next
}
}
}
This reduces the number of additional variables I need to one, but is a couple of orders of magnitude slower than the first version.
> microbenchmark::microbenchmark(factorial(100),
+ factorial_tr_1(100),
+ factorial_tr_2(100))
Unit: microseconds
expr min lq mean median uq max neval
factorial(100) 53.978 60.543 77.76203...
2014 Sep 07
2
normalizePath is sometimes very slow for nonexistent UNC paths
...uce this across machines.
The example below generates one or two slow runs out of 10000 on my
Windows machine. I haven't been able to generate slow runs on my Linux
machine, though I've had problems with slow running examples submitted
to CRAN that I suspect may be caused by this.
library(microbenchmark)
(timings <- microbenchmark(
normalizePath("\\\\some/network/drive", mustWork = FALSE),
times = 1e4,
unit = "s"
))
boxplot(timings)
Please can a few people run this code and see if they can reproduce the issue.
It isn't clear to me whether this is a bug in R or a...
2024 Feb 29
2
[External] converting MATLAB -> R | element-wise operation
I decided to do a direct comparison of transpose and sweep.
library(microbenchmark)
NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix
lambda <- c(2, 3, 4) # Example vector
colNN <- t(NN)
microbenchmark(
sweep = sweep(NN, 2, lambda, "/"),
transpose = t(t(NN)/lambda),
colNN = colNN/lambda
)
Unit: nanoseconds
expr...
2015 Nov 17
2
[RFC] A new intrinsic, `llvm.blackbox`, to explicitly prevent constprop, die, etc optimizations
...> > perfect
> >> > external world, instead to measure the overhead of an imperfect world
> >> > (by
> >> > using an empty benchmark) and subtracting that from the measured
> >> > benchmark
> >> > score.
> >>
> >> In microbenchmarks, performance is not additive. You can't compose
> >> two pieces of code and predict that the benchmark results will be the
> >> sum of the individual measurements.
> >
> >
> > This sounds like an argument against microbenchmarks in general, rather
> than...
2015 Mar 02
3
R-devel does not update the C++ returned variables
...strated a simple function.
>
>> Dirk
>
> Indeed impressive, ... and it also works with integer vectors
> something also not 100% trivial when working with compiled code.
>
> When testing that, I've went a step further:
>
> ##---- now "test":
> require(microbenchmark)
> i <- 1:10
Note that the relative speed of the algorithms also depends on the size
of the input vector. i + i becomes the winner for longer vectors (e.g. i
<- 1:1e6), but a proper Rcpp version is still approximately twice as fast.
Rcpp::cppFunction("NumericVector doubleThisNum(N...
2015 Jan 26
2
speedbump in library
...indeed.
And you, Winston, are right that this new code snippet would be
an order of magnitude faster :
##-----------------------------------------------------------------------------
f1 <- function(pkg) pkg %in% loadedNamespaces()
f2 <- function(pkg) !is.null(.getNamespace(pkg))
require(microbenchmark)
pkg <- "foo"; (mbM <- microbenchmark(r1 <- f1(pkg), r2 <- f2(pkg))); stopifnot(identical(r1,r2)); r1
## Unit: microseconds
## expr min lq mean median uq max neval cld
## r1 <- f1(pkg) 38.516 40.9790 42.35037 41.7245 42.4060 82.922 100 b...
2017 Aug 04
2
Why is as.function() slower than eval(call("function"())?
....function(list(...)). Example:
make_fn_1 <- function(a, b) eval(call("function", a, b), env = parent.frame())
make_fn_2 <- function(a, b) as.function(c(a, list(b)), env = parent.frame())
a <- as.pairlist(alist(x = , y = ))
b <- quote(x + y)
library("microbenchmark")
microbenchmark(make_fn_1(a, b), make_fn_2(a, b))
# Unit: microseconds
# expr min lq mean median uq max neval cld
# make_fn_1(a, b) 1.671 1.8855 2.13297 2.039 2.1950 9.852 100 a
# make_fn_2(a, b) 3.541 3.7230 4.13400 3.906 4.1055 23.153...
2018 Mar 14
0
Possible Improvement to sapply
>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
>>>>> on Tue, 13 Mar 2018 10:12:55 -0700 writes:
> FYI, in R devel (to become 3.5.0), there's isFALSE() which will cut
> some corners compared to identical():
> > microbenchmark::microbenchmark(identical(FALSE, FALSE), isFALSE(FALSE))
> Unit: nanoseconds
> expr min lq mean median uq max neval
> identical(FALSE, FALSE) 984 1138 1694.13 1218.0 1337.5 13584 100
> isFALSE(FALSE) 713 761 1133.53 809.5 871.5 18619 100...
2018 Feb 27
2
Parallel assignments and goto
...{
? ? ? ? ? ? ? ? escape(acc)
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? .tailr_env$.tailr_n <- n - 1
? ? ? ? ? ? ? ? .tailr_env$.tailr_acc <- n * acc
? ? ? ? ? ? ? ? .tailr_env$n <- .tailr_env$.tailr_n
? ? ? ? ? ? ? ? .tailr_env$acc <- .tailr_env$.tailr_acc
? ? ? ? ? ? }
? ? ? ? }
? ? })
}
microbenchmark::microbenchmark(factorial(1000),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_manual(1000),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_automatic_1(1000),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_automatic_2(1000))
Unit: microseconds
? ? ? ? ? ? ? ? ? ? ? ? ? ?expr ? ? min ? ? ?lq ? ? ?mean ? med...
2018 Feb 26
0
Parallel assignments and goto
...he local variables explicitly through the environment, which is what my package currently produces.
The difference between supporting non-local returns and not is tiny, but explicitly accessing variables through their environment costs me about a factor of five ? something that surprised me.
> microbenchmark::microbenchmark(factorial(1000),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_manual(1000),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_automatic_1(1000),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factorial_tr_automatic_2(1000))
Unit: microseconds
? ? ? ? ? ? ? ? ? ? ? ? ? ?expr ? ? min ? ? ? lq ? ? mean...
2015 Jan 02
3
Benchmark code, but avoid printing
Dear all,
I am trying to benchmark code that occasionally prints on the screen
and I want to
suppress the printing. Is there an idiom for this?
If I do
sink(tempfile)
microbenchmark(...)
sink()
then I'll be also measuring the costs of writing to tempfile. I could
also sink to /dev/null, which is probably fast, but that is not
portable.
Is there a better solution? Is writing to a textConnection() better?
Thanks, Best,
Gabor