-1

I have two scripts in R with similar algorithms. I would like to compare them by computational cost. How can I do this calculation?

Thanks.

Raúl

user3886573
  • 73
  • 1
  • 2
  • 11

1 Answers1

1

This is a duplicate question.

First way:

ptm <- proc.time()
#your function here
proc.time() - ptm

Or another way:

system.time({ #your function here })
Community
  • 1
  • 1
Rocketq
  • 5,423
  • 23
  • 75
  • 126
  • Are you saying that `system.time` doesn't evaluate the expression passed to it? Because that's simply wrong. Or are you just not aware that you can print, e.g., `system.time(print(1:5))`, or assign, e.g., `system.time(x <- 1:5); x` within it? – Roland Apr 22 '15 at 09:31
  • @Roland, you`re right, just checked it. – Rocketq Apr 22 '15 at 09:36
  • I mean to measure the computational cost following the big-o notation automatically – user3886573 Apr 22 '15 at 09:38
  • @user3886573 I think this experimental question, which you try get by measuring different times on diff. initial parameters. Look here http://en.wikipedia.org/wiki/Time_complexity – Rocketq Apr 22 '15 at 09:44