Stopwatch function in R

前端 未结 10 1998
后悔当初
后悔当初 2020-12-08 07:27

Is there an R timer or stopwatch function similar to MATLAB\'s tic/toc?

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 07:59

    install.packages("tictoc")
    library(tictoc)
    # Timing nested code. 
    # The string provided in the call to tic() becomes a prefix to the output of toc()
    tic("outer")
        Sys.sleep(1)
        tic("middle")
            Sys.sleep(2)
            tic("inner")
                Sys.sleep(3)
            toc() # inner
    # inner: 3.004 sec elapsed
        toc() # middle
    # middle: 5.008 sec elapsed
    toc() # outer
    # outer: 6.016 sec elapsed
    

    The tictoc package implements the functionality described by previous answers - thank you for inspiration! The package also adds nested timing, collecting the timings in user-defined variables, custom messages and callbacks.

提交回复
热议问题