C # Usage:
Public Static classQUERYPERFORMANCEMETHD {[DllImport ("Kernel32.dll")] Public extern Static ShortQueryPerformanceCounter (ref Longx); [DllImport ("Kernel32.dll")] Public extern Static ShortQueryPerformanceFrequency (ref Longx); }
Staticvoid Main (String[] args) {Long Stop_value =0;Long Start_value =0;Long freq =0; Queryperformancemethd.queryperformancefrequency (ref freq); Queryperformancemethd.queryperformancecounter (ref start_value); //Fun() requires a timing method Queryperformancemethd.queryperformancecounter (ref stop_value); Double time = (double) (stop_value-start_value)/(double) (Freq); Console.WriteLine (time); // unit S console.readline ();}
The calculated time is consumed by the fun () method.
Usage of QueryPerformanceCounter QueryPerformanceFrequency in C + +
#include"stdafx.h"#include"windows.h"voidMain () {Large_integer nfreq; Large_integer Nbegintime; Large_integer Nendtime; DoubleTime ; QueryPerformanceFrequency (&nfreq); QueryPerformanceCounter (&nbegintime); Sleep ( +); QueryPerformanceCounter (&nendtime); time= (Double) (Nendtime.quadpart-nbegintime.quadpart)/(Double) Nfreq.quadpart; printf ("%f\n", time); System ("Pause");}
Calculates the exact time consumed by sleep (1000), not the exact 1s
QueryPerformanceCounter queryperformancefrequency usage of C # precision timekeeping