From 902d5df48b49a4e03dcd4f0af280f4906c127e41 Mon Sep 17 00:00:00 2001 From: prdm0 Date: Tue, 23 Apr 2024 09:36:07 -0300 Subject: [PATCH] Update test-time-parallel.R --- tests/testthat/test-time-parallel.R | 44 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/tests/testthat/test-time-parallel.R b/tests/testthat/test-time-parallel.R index 651c12b..01f693c 100644 --- a/tests/testthat/test-time-parallel.R +++ b/tests/testthat/test-time-parallel.R @@ -1,18 +1,30 @@ -simulation <- function(parallel = FALSE){ - time <- system.time( - x <- accept_reject( - n = 2e6L, - f = dnorm, - continuous = TRUE, - args_f = list(mean = 0, sd = 1), - xlim = c(-4, 4), - parallel = FALSE - )) - list(time = time, x = x) -} +simulation <- function(n, parallel = FALSE){ + # Iniciar o tempo + start_time <- Sys.time() + + # Executar a função accept_reject + x <- accept_reject( + n = n, + f = dnorm, + continuous = TRUE, + args_f = list(mean = 0, sd = 1), + xlim = c(-4, 4), + parallel = parallel + ) + + # Calcular o tempo de execução + end_time <- Sys.time() + execution_time <- end_time - start_time -# Serial -cat(simulation(parallel = FALSE)) + # Imprimir o tempo de execução + cat("Tempo de execução: ", execution_time, " segundos\n") -# Parallel -cat(simulation(parallel = TRUE)) + # Imprimir as primeiras observações + cat("Primeiras observações:\n") + print(head(x)) + + # Retornar o resultado + return(x) +} +simulation(n = 3e6L, parallel = FALSE) +simulation(n = 3e6L, parallel = TRUE)