Dear R users and experts, I am current running a program (a series of commands) in R. such as: A <- as.matrix(read.table("C:/LP.txt")); a=which(memb==q); b=a; B=as.matrix(A[a,b]) LS=sum(B)/2; TL=sum(A)/2 i<-c(1:NN); D=sum(A[a,i]); how can i obtain the CPU time used for these commands ? I have seen the system.time function but i am not sure how to use it. Could anyone help me ? ****** If we have a number of commands, how can we know the CPU for these commands ******* Thanks a lot for your time and help Have a nice day! Warm Regards Marshall [[alternative HTML version deleted]]
-------- Original Message -------- Subject: [R] how to obtain the CPU time of my program From: gang xu <ucecgxu at ucl.ac.uk> To: r-help at stat.math.ethz.ch Date: 13.09.2007 17:16> Dear R users and experts, > > I am current running a program (a series of commands) in R. such as: > > A <- as.matrix(read.table("C:/LP.txt")); > > a=which(memb==q); b=a; B=as.matrix(A[a,b]) > > LS=sum(B)/2; > > TL=sum(A)/2 > > i<-c(1:NN); > > D=sum(A[a,i]); > > how can i obtain the CPU time used for these commands ? > > I have seen the system.time function but i am not sure how to use it. Could anyone help me ? >?system.time> ****** If we have a number of commands, how can we know the CPU for these commands ******* > > > Thanks a lot for your time and help > > Have a nice day! > > Warm Regards > > Marshall > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-=-=- ... Those people who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)
Here's how to use it: f <- function() { <<here comes your code>> } system.time( f() ) It is not required to define a function, but i think it is easier. Gabor On Thu, Sep 13, 2007 at 04:16:45PM +0100, gang xu wrote:> Dear R users and experts, > > I am current running a program (a series of commands) in R. such as: > > A <- as.matrix(read.table("C:/LP.txt")); > > a=which(memb==q); b=a; B=as.matrix(A[a,b]) > > LS=sum(B)/2; > > TL=sum(A)/2 > > i<-c(1:NN); > > D=sum(A[a,i]); > > how can i obtain the CPU time used for these commands ? > > I have seen the system.time function but i am not sure how to use it. Could anyone help me ? > > ****** If we have a number of commands, how can we know the CPU for these commands ******* > > > Thanks a lot for your time and help > > Have a nice day! > > Warm Regards > > Marshall > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
Hi, first of all 'sorry' for my rather late post on this topic... Did you already came across the R command 'Rprof' ? This might help you to find answers to your problem in terms of CPU time/command. I use 'Rprof' like this:>Rprof() >source("yourCode.R") >Rprof(NULL)This produces a file called Rprof.out in your working directory. Quit R and type 'R CMD Rprof Rprof.out'. I am too new in using those profiling methods of R but I think they are pretty handy. Try out ?Rprof for detailed information. Cheers, Christian gang xu wrote:> Dear R users and experts, > > I am current running a program (a series of commands) in R. such as: > > A <- as.matrix(read.table("C:/LP.txt")); > > a=which(memb==q); b=a; B=as.matrix(A[a,b]) > > LS=sum(B)/2; > > TL=sum(A)/2 > > i<-c(1:NN); > > D=sum(A[a,i]); > > how can i obtain the CPU time used for these commands ? > > I have seen the system.time function but i am not sure how to use it. Could anyone help me ? > > ****** If we have a number of commands, how can we know the CPU for these commands ******* > > > Thanks a lot for your time and help > > Have a nice day! > > Warm Regards > > Marshall > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Christian Kohler Institute of Functional Genomics Computational Diagnostics University of Regensburg (BioPark I) D-93147 Regensburg (Germany) Tel. +49 941 943 5055 Fax +49 941 943 5020 christian.kohler at klinik.uni-regensburg.de