0

How can I create simply stopwatch in milliseconds? (on windows) I need it in C, not C++! on linux, I used:

#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <sys/times.h>
#include <sys/unistd.h>

int main(){  

    struct tms timeStruct;
    clock_t timeStart;  ///struktura - zaciatok merania casu 
    clock_t timeEnd;    ///struktura - koniec merania
    time_t aktual;
    time(&aktual);
    int tickPerSeconds = sysconf(_SC_CLK_TCK);


    timeStart = times(&timeStruct);
    int i,j;
    for(i=0;i<10000;i++)
        for(j=0;j<10000;j++);

    timeEnd = times(&timeStruct);

    printf("time: %.1f [sec]\n",(timeEnd - timeStart) / (double) tickPerSeconds);   ///vypis na obrazovku

   return 0;
}

but I need something else.... I need it on windows.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Can you not compile this with a Windows C compiler? http://www.mingw.org/ – Dimitris Sfounis Dec 16 '14 at 09:24
  • @DimitrisSfounis This is not standard C. The libraries that are used are not readily available on Windows. – David Heffernan Dec 16 '14 at 09:30
  • Your question is lacking a language tag. The “duplicate” question might have an appropriate answer if you are coding in C. For C++ (as the linked question is tagged), the [`std::chrono`](http://en.cppreference.com/w/cpp/chrono/system_clock) library should be used as a portable solution in new (C++11) code. – 5gon12eder Dec 16 '14 at 09:31
  • does not recognize #include #include –  Dec 16 '14 at 09:31

0 Answers0