Skip to content

Commit

Permalink
fix benchmarking issue with multiple reps
Browse files Browse the repository at this point in the history
  • Loading branch information
wrathematics committed Dec 16, 2021
1 parent 2d77fd8 commit f79b111
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
*.status
*~
*.swp

3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Release 0.3-1:
* Fixed bug in bench timer with reps>1.

Release 0.3-0:
* Cleaned up some internals.
* Fix installation documentation issue.
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Package: merkhet
Type: Package
Title: Time Utilities for R
Version: 0.3-0
Version: 0.3-1
Description: The name 'merkhet' is an ancient word for a kind of timekeeping
device, which means the "instrument of knowing." The package contains
several timing utilities useful for 'benchmarking' and performance
monitoring.
License: BSD 2-clause License + file LICENSE
Depends:
R (>= 3.0.0)
R (>= 3.6.0)
Imports:
R6 (>= 2.4.1)
ByteCompile: yes
Authors@R: person("Drew", "Schmidt", role=c("aut", "cre"), email="[email protected]")
Maintainer: Drew Schmidt <[email protected]>
URL: https://github.com/shinra-dev/merkhet
BugReports: https://github.com/shinra-dev/merkhet/issues
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
HPCRAN: benchmark
21 changes: 12 additions & 9 deletions R/bench.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ benchR6 = R6::R6Class("bench",
private$elapsed = numeric(0)
private$n = 0
},





#' @details
#' Time an expression using \code{system.time()}.
#' @param expr Expression to time.
Expand All @@ -36,22 +37,24 @@ benchR6 = R6::R6Class("bench",
private$n = private$n + 1
private$reps = c(private$reps, as.integer(reps))

expr_subs = substitute(expr)

if (is.null(name))
name = deparse(substitute(expr))

private$names = c(private$names, name)

t = 0
for (rep in 1:reps)
t = t + system.time(eval(expr, envir=env))[3]
t = t + system.time(eval(expr_subs, envir=env))[3]

private$elapsed = c(private$elapsed, t)

invisible(self)
},



#' @details
#' Print current benchmark information.
print = function()
Expand Down Expand Up @@ -180,9 +183,9 @@ benchR6 = R6::R6Class("bench",
invisible(self)
}
),



private = list(
header = NULL,
flops = NULL,
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# merkeht

* **Version:** 0.3-0
* **Version:** 0.3-1
* **License:** [BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause)
* **Project home**: https://github.com/shinra-dev/merkhet
* **Bug reports**: https://github.com/shinra-dev/merkhet/issues
Expand Down Expand Up @@ -98,23 +98,23 @@ b$time(Sys.sleep(.3), reps=2)
b
## ## Benchmark of 1 operations
## elapsed reps avg relative
## Sys.sleep(0.3) 0.301 2 0.1505 1
## Sys.sleep(0.3) 0.6 2 0.3 1

b$time(Sys.sleep(.5))
b
## ## Benchmark of 2 operations
## elapsed reps avg relative
## Sys.sleep(0.3) 0.301 2 0.1505 1.00
## Sys.sleep(0.5) 0.501 1 0.5010 1.66
## Sys.sleep(0.3) 0.6 2 0.3 1.2
## Sys.sleep(0.5) 0.5 1 0.5 1.0
```

There is also an option to dump the data to csv (file or stdout):

```r
b$csv()
## expr,elapsed,reps,avg,relative
## "Sys.sleep(0.3)",0.301,2,0.1505,1
## "Sys.sleep(0.5)",0.501,1,0.501,1.66
## "Sys.sleep(0.3)",0.6,2,0.3,1.2
## "Sys.sleep(0.5)",0.5,1,0.5,1
```

as well as make simple boxplots
Expand Down

0 comments on commit f79b111

Please sign in to comment.