how to calculate system time

This is a discussion on how to calculate system time within the C Programming forums, part of the General Programming Boards category; PHP Code:     double wall_time ;      struct rusage ru_start ,  ru_end ;      getrusage ( RUSAGE_SELF , & ru_start );      mergesort ( args ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    how to calculate system time

    PHP Code:
        double wall_time;
        
    struct rusage ru_startru_end;
        
    getrusage(RUSAGE_SELF, &ru_start);
        
    mergesort(args[i], sizeof(original)/sizeof(*original), sizeof(*original),my_cmp); /*my program that need to be measued*/
        
    getrusage(RUSAGE_SELF, &ru_end);
        
    sys_time ru_end.ru_stime.tv_sec ru_start.ru_stime.tv_sec;
        
    sys_time += (ru_end.ru_stime.tv_usec ru_start.ru_stime.tv_usec)/1000000.0;
        print(
    "%f",sys_time); 
    im tying to the system time my program uses, but all i get is 0, what should i do?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Does it print 0, even when it's obviously taking a lot longer?

    How big is the array you're sorting?

    getrusage
    Returns success / fail (you don't check)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Time for a new system....again
    By VirtualAce in forum Tech Board
    Replies: 6
    Last Post: 06-18-2007, 06:48 AM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  3. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 06:11 AM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. Passing system time to a function
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 12:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21