R/timer.R

Defines functions timeSequence

Documented in timeSequence

#' Time each index evaluation for projections in the tour path.
#'
#' Index evaluation timing may depend on the data distribution, we
#' evaluate the computing time for a set of different projections to
#' get an overview of the distribution of computing times.
#'
#' @param d Input data in matrix format
#' @param t List of projection matrices (e.g. interpolated tour path)
#' @param idx Index function
#' @param pmax Maximum number of projections to evaluate (cut t if longer than pmax)
#' @return numeric vector containing all distances
#' @export
#' @examples \donttest{
#' d <- spiralData(4, 1000)
#' t <- purrr::rerun(10, tourr::basis_random(4))
#' idx <- scagIndex("Skinny")
#' timeSequence(d, t, idx, 10)
#' }
timeSequence <- function(d, t, idx, pmax){
  i <- 1
  dfTimer <- data.frame(t= numeric(), i=numeric())
  for(pMatrix in t){
    if(i>pmax) break
    tictoc::tic.clearlog()
    tictoc::tic() #start timer
    dProj <- d %*% pMatrix
    res <- idx(dProj)
    tictoc::toc(log=TRUE,quiet=TRUE)
    resT <- unlist(tictoc::tic.log(format=FALSE))["toc.elapsed"] -
      unlist(tictoc::tic.log(format=FALSE))["tic.elapsed"]
    dfTimer <- tibble::add_row(dfTimer, t=resT, i=i)
    i <- i+1
  }
  return(dfTimer)
}

Try the spinebil package in your browser

Any scripts or data that you put into this service are public.

spinebil documentation built on Aug. 28, 2019, 5:04 p.m.