0
#include <stdio.h>
#include <time.h>
#include <windows.h>

void Task()
{
    printf("Hi");
}

int main ( ) {
    time_t t;
    clock_t start, end;
    long i;
    long count;
    double x = 0.0;
    count = 2;

    start = clock();

    time(&t);

    printf(ctime(&t));
    printf( "Counting to %ld\n", count );

    if(count)
    {
        Task();
    }

    end = clock();

    printf( "That took %f seconds and I counted up to %ld", (((double)(end-start)/CLOCKS_PER_SEC)), count );
    printf( "\nThat also took %d clock tics\n ", clock());
    return 0;
} 

Task 関数の実行にかかった開始時刻と終了時刻を取得したいと考えています。Task 関数の割り込みを作成しようとしていますが、プログラムに Hi が表示されます。私はそれで成功していません。ですから、これに関して誰かが私を導くことができますか?

4

3 に答える 3

1

マルチメディア タイマーから始めてみてください。別の可能なアプローチは、CreateTimerQueueTimer()and friendsを使用することです。

于 2013-11-04T15:43:55.143 に答える
0

議論後の新しい回答 (以前の回答のコメントを参照): GetStopWatch() 関数に相当するものを次のように実装できます。

#include <windows.h>
#include <stdio.h>
#include <stdint.h>

// assuming we return times with microsecond resolution
#define STOPWATCH_TICKS_PER_US  1

uint64_t GetStopWatch()
{
    LARGE_INTEGER t, freq;
    uint64_t val;

    QueryPerformanceCounter(&t);
    QueryPerformanceFrequency(&freq);
    return (uint64_t) (t.QuadPart / (double) freq.QuadPart * 1000000);
}

void task()
{
    // do something...
}

int main()
{
  uint64_t start = GetStopWatch();
  task();
  uint64_t stop = GetStopWatch();

  printf("Elapsed time (microseconds): %lld\n", stop - start);
}

お役に立てれば。

于 2013-11-06T21:00:35.280 に答える