Skip to contents

r8bench(expr) evaluates expr once, in the caller's frame, and returns a record of the resources that it took: the wall time, the CPU time of R's process, the most memory that the process held, the cores that it may use, and, for each call of r8map(), r8summarize(), or r8set() that expr runs, the plan of the call filled by its run: each stage's status, its first start and last end in seconds from the call's start, and the seconds it was busy, and a failed stage's group, first row, and message. The record prints as one line.

Usage

r8bench(expr, gc = FALSE)

# S3 method for class 'r8_bench'
format(x, ...)

# S3 method for class 'r8_bench'
print(x, ...)

Arguments

expr

An expression, evaluated once in the caller's frame.

gc

Logical: Collect R's heap before expr and measure the most that it held during it.

x

An r8_bench.

...

Not used.

Value

An r8_bench: a list of wall, cpu_user, and cpu_system, seconds; utilization; n_threads, the most threads that the plans' work may use, or the default of n_threads without a plan; cores_available; rss_start and rss_peak, bytes; process_peak_before and process_peak_after, bytes; r_heap_peak, bytes, or NULL without gc = TRUE; rust_heap_peak, NULL; where, the engine of the plans' work, "rust", "r", or "rust+r", and the calls of typed functions with their bodies in Rust and in R, or NULL without a plan; size, the most rows and groups of the plans and their calls; plans, a list of r8_plan; platform; and r8_version. A figure that the operating system does not give is NA. An error of expr is raised after the measurement ends.

Measures

The CPU time, in user and in system mode, is that of all the threads of R's process, from getrusage() or GetProcessTimes(); utilization is its ratio to the wall time, the threads busy on average. The wall time and the times of the stages are read from a monotonic clock. rss_peak is the most memory that the process held during expr, read about every 10 ms by a thread of Rust that calls no function of R, which starts before the times measured and stops after them; process_peak_before and process_peak_after are the operating system's high-water mark of the process, which a peak during expr raises and which macOS does not reset. cores_available is the cores that the operating system gives the process, and at most SLURM_CPUS_PER_TASK in a Slurm job. With gc = TRUE, R's heap is collected before expr, outside the time measured, and r_heap_peak is the most memory that R's heap held during it. The plans are those that r8explain() gives, filled by the run. A time under 1 s prints in milliseconds.

Examples

op <- options(r8.namespace = "demo")
m <- Raven(
  combo = rep(1:20, each = 10),
  auc = seq(0.7, 0.9, length.out = 200)
)
b <- r8bench(r8map(m, calc(mean(col())), by = "combo"))
b
#> r8bench(): 0.70 ms, CPU 0.73 ms (1.0 of 5 threads), memory peak 244 MiB, in Rust
b$wall
#> [1] 0.000702666
as.data.frame(b$plans[[1L]])
#>   node_id     stage    label engine function language calls threads inputs
#> 1      s2     check               r     <NA>     <NA>    NA   FALSE       
#> 2      s3   compile            rust     <NA>     <NA>    NA   FALSE     s2
#> 3      s4     group by combo   rust     <NA>     <NA>    NA   FALSE     s2
#> 4      s5 aggregate            rust     <NA>     <NA>    NA   FALSE s3, s4
#> 5      s6  assemble               r     <NA>     <NA>    NA   FALSE     s5
#>      status     t_start       t_end       busy
#> 1 completed 0.000000000 0.000349250 3.4925e-04
#> 2 completed 0.000353375 0.000357417 4.0420e-06
#> 3 completed 0.000349250 0.000353375 4.1250e-06
#> 4 completed 0.000383959 0.000386417 2.4580e-06
#> 5 completed 0.000434334 0.000469959 3.5625e-05