Thread: How to implement "time" in Windows ?

  1. #1
    Registered User TmX's Avatar
    Join Date
    Sep 2006

    How to implement "time" in Windows ?

    In *nix, there the time utility for measuring the execution time of a command

    I'm interested in writing my own, so here's my quick attempt :
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    int main(int argc, char *argv[]){
    	clock_t start,end;
    	int x;
    	char command[100];
    	if (argc > 1){
    		strcpy(command," ");
    		for (x = 1; x < argc; x++){
    			strcat(command," ");
    		start = clock();
    		end = clock();
    	return 0;
    I don't think it perform correctly, probably due to the overhead caused by system().
    How can I make it more accurate ? Maybe some Win32 API needed ?

  2. #2

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Describe "not working properly". Yes, system will have some overhead, but that's not necessarily the only reason. If you really want to precisely measure another process, you probably will want to use CreateProcess() so that you can control the process better, and use GetProcessTimes() to get the time used by that process.

    Yes, that's a whole lot more complicated, but it's more precise - unfortunately, there's no SIMPLE way to do that.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Top Level Windows
    By quark_77 in forum Windows Programming
    Replies: 0
    Last Post: 07-13-2008, 02:32 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM