Home > Mobile >  Tracking runtime in seconds
Tracking runtime in seconds

Time:11-14

I'm creating machine learning models and in order to score the performance of my models, one aspect that I am looking at is the time that it takes for the model to run.

I have the following code:

  start_time <- Sys.time()
  predictions <- class.tree.predictions(traindata, testdata)
  end_time <- Sys.time()
  run_time <- end_time - start_time

When there is a time difference of seconds the output is "Time difference of 0.23204 sec" but when the time difference is in minutes the output is "Time difference of 1.05204 mins".

I need the output to only be in seconds, or I need an if statement for when the time difference is in minutes, so it can get multiplied by 60, but I'm not sure how to go about it.

CodePudding user response:

difftime has an option for units:

difftime(end_time, start_time, units="secs")
  • Related