• <small id='BDgcQ'></small><noframes id='BDgcQ'>

    <tfoot id='BDgcQ'></tfoot>
    • <bdo id='BDgcQ'></bdo><ul id='BDgcQ'></ul>

    <i id='BDgcQ'><tr id='BDgcQ'><dt id='BDgcQ'><q id='BDgcQ'><span id='BDgcQ'><b id='BDgcQ'><form id='BDgcQ'><ins id='BDgcQ'></ins><ul id='BDgcQ'></ul><sub id='BDgcQ'></sub></form><legend id='BDgcQ'></legend><bdo id='BDgcQ'><pre id='BDgcQ'><center id='BDgcQ'></center></pre></bdo></b><th id='BDgcQ'></th></span></q></dt></tr></i><div id='BDgcQ'><tfoot id='BDgcQ'></tfoot><dl id='BDgcQ'><fieldset id='BDgcQ'></fieldset></dl></div>
    <legend id='BDgcQ'><style id='BDgcQ'><dir id='BDgcQ'><q id='BDgcQ'></q></dir></style></legend>

        C++中的时差

        Time difference in C++(C++中的时差)
        <tfoot id='OhZ0q'></tfoot>
      1. <small id='OhZ0q'></small><noframes id='OhZ0q'>

            <bdo id='OhZ0q'></bdo><ul id='OhZ0q'></ul>
            <legend id='OhZ0q'><style id='OhZ0q'><dir id='OhZ0q'><q id='OhZ0q'></q></dir></style></legend>

              <tbody id='OhZ0q'></tbody>

                <i id='OhZ0q'><tr id='OhZ0q'><dt id='OhZ0q'><q id='OhZ0q'><span id='OhZ0q'><b id='OhZ0q'><form id='OhZ0q'><ins id='OhZ0q'></ins><ul id='OhZ0q'></ul><sub id='OhZ0q'></sub></form><legend id='OhZ0q'></legend><bdo id='OhZ0q'><pre id='OhZ0q'><center id='OhZ0q'></center></pre></bdo></b><th id='OhZ0q'></th></span></q></dt></tr></i><div id='OhZ0q'><tfoot id='OhZ0q'></tfoot><dl id='OhZ0q'><fieldset id='OhZ0q'></fieldset></dl></div>

                  本文介绍了C++中的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有谁知道如何在 C++ 中以毫秒为单位计算时间差?我使用了 difftime 但它没有足够的精度我正在尝试测量什么.

                  Does anyone know how to calculate time difference in C++ in milliseconds? I used difftime but it doesn't have enough precision for what I'm trying to measure.

                  推荐答案

                  您必须使用一种更具体的时间结构,timeval(微秒分辨率)或 timespec(纳秒分辨率),但您可以手动进行相当容易:

                  You have to use one of the more specific time structures, either timeval (microsecond-resolution) or timespec (nanosecond-resolution), but you can do it manually fairly easily:

                  #include <time.h>
                  
                  int diff_ms(timeval t1, timeval t2)
                  {
                      return (((t1.tv_sec - t2.tv_sec) * 1000000) + 
                              (t1.tv_usec - t2.tv_usec))/1000;
                  }
                  

                  如果时间差异非常大(或者如果您有 16 位整数),这显然存在整数溢出问题,但这可能不是常见情况.

                  This obviously has some problems with integer overflow if the difference in times is really large (or if you have 16-bit ints), but that's probably not a common case.

                  这篇关于C++中的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                1. <legend id='l1nTx'><style id='l1nTx'><dir id='l1nTx'><q id='l1nTx'></q></dir></style></legend>
                  • <bdo id='l1nTx'></bdo><ul id='l1nTx'></ul>

                        <tbody id='l1nTx'></tbody>
                      1. <tfoot id='l1nTx'></tfoot>

                          <small id='l1nTx'></small><noframes id='l1nTx'>

                            <i id='l1nTx'><tr id='l1nTx'><dt id='l1nTx'><q id='l1nTx'><span id='l1nTx'><b id='l1nTx'><form id='l1nTx'><ins id='l1nTx'></ins><ul id='l1nTx'></ul><sub id='l1nTx'></sub></form><legend id='l1nTx'></legend><bdo id='l1nTx'><pre id='l1nTx'><center id='l1nTx'></center></pre></bdo></b><th id='l1nTx'></th></span></q></dt></tr></i><div id='l1nTx'><tfoot id='l1nTx'></tfoot><dl id='l1nTx'><fieldset id='l1nTx'></fieldset></dl></div>