Am I right in a way to measure CPU time consumed by a block of code?

Discussion in 'Java' started by www, Apr 5, 2007.

  1. www

    www Guest

    Hi,

    I want to measure the CPU time, not the "apparent" user time, consumed
    by a block of code in my Java program. This Java program was translated
    from Fortran program and now we want to do some bench mark to compare
    with its original Fortran program, but we don't want to count those I/O
    operations. We just want to focus on the block of code doing heavy duty
    scientific computations. The command

    time java MyJavaClassName

    will give the user time and system time spent for the whole program from
    beginning to the end.

    I came a "silly" idea for measuring the system time used by the block of
    code we are interested in by using "time" command:

    for(int i=1; i<=20; i++)
    {
    //code for doing computation
    }

    Then

    time java MyJavaClassName

    The extra system time is due to 19 runs of computation. The extra system
    time used divided it by 19 gives me the system time for a single
    computation.

    Am I right? Thank you.
     
    www, Apr 5, 2007
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanjay
    Replies:
    4
    Views:
    815
    Sanjay
    Nov 20, 2003
  2. morrell
    Replies:
    1
    Views:
    1,220
    roy axenov
    Oct 10, 2006
  3. Replies:
    5
    Views:
    502
    Raymond
    Aug 20, 2006
  4. Replies:
    8
    Views:
    558
    bitkidoku
    Jun 20, 2006
  5. www
    Replies:
    14
    Views:
    772
  6. www
    Replies:
    1
    Views:
    527
  7. Shadow of Socrates
    Replies:
    0
    Views:
    524
    Shadow of Socrates
    Jan 22, 2008
  8. Shadow of Socrates

    [C#] How to measure the time of your code's execution

    Shadow of Socrates, Jan 22, 2008, in forum: C Programming
    Replies:
    0
    Views:
    367
    Shadow of Socrates
    Jan 22, 2008
Loading...