Thread: time for console appz

  1. #1
    Unregistered
    Guest

    time for console appz

    ok, i've been trying to think of a way for my program to run at the same speed on any computer, because of its long delays (ex: for loops) i was thinking of using a counter at the begining of the program to see how fast it is. what i figured was to run a while loop and count the amount of times it could run a small equatioin [x++] in 1 minute and then calibrate the program from there. unfortunitly, time.h is a ... yea and i can't figure out how to get the time from the computer. if someone could just tell me that it'd be very very helpful... latez

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    66

    apps...

    Running loops to measure time is useless for most parts as the OS controls multi-tasking. You will need to set your program priority to real-time, then run tests. Or use high resolution callback timers (eg. multimedia timers in windows). Using execution of code to measure time is only valid if the only process running is your application, which is never the case with most modern OSs.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    317
    This code will give you a delay defined by secs and it will be constant from system to system:
    Code:
    #include<iostream>
    #include<ctime> //or time.h
    
    using namespace std;
    
    int main() {
               float secs = 5; //define delay
               clock_t delay = secs*CLOCKS_PER_SEC; //convert clock ticks
               clock_t start = clock();
               while (clock() - start <delay);
               return(0);
    }
    This converts secs to computer clock ticks therefore will be the same from system to system.

  4. #4
    Unregistered
    Guest
    ok, yea.. the code seemed to work... i'm haveing a friend test the speed changes on his machine.. but thanx ya'll

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM