One - One Code All

Blog Content

R语言记录程序运行时间

R语言   2010-04-27 23:02:37


# 函数:

f <- function(start_time) {

  start_time <- as.POSIXct(start_time)

  dt <- difftime(Sys.time(), start_time, units="secs")

  # Since you only want the H:M:S, we can ignore the date...

  # but you have to be careful about time-zone issues

  format(.POSIXct(dt,tz="GMT"), "%H:%M:%S")

}


# how to use:


time1<-Sys.time()

# 中间是自己的程序

f(time1)  #如果是用脚本执行,此行代码可以用  print(f(time1)) 代替


# R记录程序运行时间

classiftime1 <- proc.time()  # record classification time 


#这里是需要记录时间的代码

#  比如用支持向量机做分类

svm211 <-svm(Yc1~., data = hvsplit1 , # without selected festures  class~., data = hvc1,

             scale = TRUE, 

             type = "C-classification", 

             kernel ="radial",  

             gamma = 0.9 ,   #  1/ncol(hvsplit1) 

             cost = 300, 

             class.weights = NULL,

             cachesize = 10, 

             tolerance = 0.1, 

             epsilon = 0.1,

             shrinking = TRUE, 

             cross = 10, 

             probability = TRUE, 

             fitted = TRUE,

             na.action = na.omit,

             metric="ROC")


#

classiftime <-  proc.time() - classiftime1 



上一篇:R语言使用命令行参数运行R脚本程序
下一篇:R语言apply()函数用法

The minute you think of giving up, think of the reason why you held on so long.