QueryPerformanceCounter queryperformancefrequency usage of C # precision timekeeping

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.