R语言中如何记录程序运行的时间
1、
start <- Sys.time() ## 记录 Sys.sleep(20) ## 停止20s end <- Sys.time() ## 记录 elapse <- end - start ## 计算 print(elapse) ## 打印
2、
start <- Sys.time() Sys.sleep(70) end <- Sys.time() elapse <- end - start print(elapse) ## 自动转换时间输出格式
3、写入文件
start <- Sys.time() Sys.sleep(70) ## commands end <- Sys.time() process <- paste(start, end, sep = "---") write.table(process, "time.txt") elapsed <- as.numeric(difftime(end, start, units = 'sec')) write.table(elapsed, "time.txt", row.names = "secs:", col.names = F,append = T)