Skip to content

Commit

Permalink
Add benchmark for Render.
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Dec 22, 2023
1 parent 250c388 commit c9cdee3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
61 changes: 61 additions & 0 deletions tests/performance/bench-render.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# bench-render.R
#
# Created on: 22 Dec 2023
# Author: pl2113
#

library(individual)
library(bench)
library(ggplot2)
library(scales)

source("./tests/performance/utils.R")

render_single <- bench::press(
timesteps=floor(10^seq(3,6,0.25)),
{
render <- Render$new(timesteps)
bench::mark(
min_iterations = 50,
check = FALSE,
render={
# Use timesteps/2 to write in the middle of the array
render$render("data", 0.5, timesteps/2)
})
})

render_single %>%
simplify_bench_output() %>%
ggplot() +
aes(x = timesteps, y = as.numeric(time), color=expression, fill=expression, group=as.factor(timesteps):expression) +
geom_violin(position=position_dodge(width=0.02), alpha=0.3) +
labs(y="time", fill="expression", color="expression") +
scale_x_continuous(trans='log10', n.breaks=6, labels = label_comma()) +
scale_y_continuous(trans='log10', n.breaks=6, labels = function(x) format(bench::as_bench_time(x))) +
ggtitle("Render single timestep benchmark")

render_all <- bench::press(
timesteps=floor(10^seq(3,5,0.25)),
{
data <- runif(timesteps)
bench::mark(
min_iterations = 5,
check = FALSE,
filter_gc = FALSE,
render_all={
render <- Render$new(timesteps)
mapply(function(x, i) render$render("data", x, i), data, seq_along(data))
})
})

render_all %>%
simplify_bench_output(filter_gc=FALSE) %>%
ggplot() +
aes(x = timesteps, y = as.numeric(time), color=expression, fill=expression, group=as.factor(timesteps):expression) +
geom_violin(position=position_dodge(width=0.01), alpha=0.3) +
labs(y="time", fill="expression", color="expression") +
scale_x_continuous(trans='log10', n.breaks=6, labels = label_comma()) +
scale_y_continuous(trans='log10', n.breaks=6, labels = function(x) format(bench::as_bench_time(x))) +
ggtitle("Render all timesteps benchmark")

7 changes: 5 additions & 2 deletions tests/performance/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ create_random_index_bitset <- function(size, limit) {
#' @description Unnest output to generate histograms or density plots, and remove
#' all runs where any level of garbage collection was executed.
#' @param out output of [bench::press] function
simplify_bench_output <- function(out) {
simplify_bench_output <- function(out, filter_gc=TRUE) {
x <- lapply(X = seq_len(nrow(out)), FUN = function(i) {
# get gc level (if run) as factor
gc <- rep("none", times = nrow(out$gc[[i]]))
Expand All @@ -66,7 +66,10 @@ simplify_bench_output <- function(out) {
return(out_i)
})
out_format <- do.call(what = rbind, args = x)
out_format <- out_format[out_format$gc == "none", ]
if (filter_gc)
{
out_format <- out_format[out_format$gc == "none", ]
}
out_format$expression <- as.factor(attr(out_format$expression, "description"))
return(out_format)
}
Expand Down

0 comments on commit c9cdee3

Please sign in to comment.