Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ precision performance test function     - Ubuntu 15.04 and CentOS 7 to deploy .NET, Mono and DNX (Server)

- Ubuntu 12.04 64bit Install Source Insight 3.5 and create desktop icons (Linux)

- Getting Started with Linux system to learn: how to install the Shrew Soft IPsec VPN on Linux (Linux)

- Learning UNIX good habits (Linux)

- Nodejs nano library to handle couchdb: need a timeout (Database)

- How LUKS encrypted disk / partition to perform remote incremental backup (Linux)

- Ubuntu 14.10 / 14.04 how to install Quick Start tool Mutate 2.2 (Linux)

- Ant command-line compiler Android project (Programming)

- init level settings for Linux / etc / inittab file into six (restart) or does not support the level of solution (Linux)

- VMware ghost Linux card error (Linux)

- Linux cut Command Study Notes (Linux)

- CentOS 6.6 command-line automatic completion (Linux)

- MySQL5.7.10 installation documentation (Database)

- Linux non-graphical interface to install Oracle Database (Database)

- How to Install Redis server on CentOS 7 (Server)

- Good wireless network security information spread in the air (Linux)

- PHP 5.3 New Features Detail (Linux)

- Apache2.4.7 make an error [exports.lo] Error 1 Solution (Server)

- LVM management reduces swap partition space to the root partition (Linux)

- JEdit 5.2 Pro Edition installation on Ubuntu 14.04 (Linux)

 
         
  C ++ precision performance test function
     
  Add Date : 2018-11-21      
         
       
         
  In the actual software development work, we often test the efficiency of a module or function. Or is the time complexity of an algorithm (although the time depends on the complexity of the machine performance to some extent, but on the same computer, through algorithm optimization, you can test its complexity); this time you need to get the exact time, we can accurate running time, the following function to achieve a precise timing, timing accuracy can reach microsecond; can be used to test the efficiency of a module!

// Purpose: this programme is designed for testing the performance of your code, some function ect,
// It can show the time of spending on your running on it. It is beneficial to improve your performance
// Of code

#include < Windows.h>
#include < iostream>
#include < tchar.h>
using namespace std;
#define IN

#ifdef _DEBUG
#define _Trace_Size 500
inline void FileTrace (IN LPCTSTR szFormat, ...)
{
 if (szFormat == NULL)
  return;

 TCHAR t_trace [_Trace_Size] = {_T ( '\ 0')};
 va_list vl = NULL;

 // Generated Content
 va_start (vl, szFormat);
 _vsntprintf_s (t_trace, _Trace_Size, _TRUNCATE, szFormat, vl);
 va_end (vl);
 OutputDebugString (t_trace);
}
#else
inline void FileTrace (IN LPCTSTR szFormat, ...) {}
#endif

LARGE_INTEGER begin_time, freq;

int main ()
{
 LARGE_INTEGER begin_time, freq;
 QueryPerformanceFrequency (& freq);
 QueryPerformanceCounter (& begin_time);
    // Begin time
    for (long test0 = 0; test0 < 5000000; test0 ++)
    {
  test0 = test0 + 1;
    }
 LARGE_INTEGER end_time0;

  QueryPerformanceCounter (& end_time0);
 // After runnin the 'for' loop statement, the time is Time0
  double Time0 = ((double) (end_time0.QuadPart - begin_time.QuadPart) * 1000.0) / (double) (freq.QuadPart);

    int test1 = 10000;
 while (test1)
 {
  test1--;
 }
  LARGE_INTEGER end_time1;
 QueryPerformanceCounter (& end_time1);
  double Time1 = ((double) (end_time1.QuadPart - begin_time.QuadPart) * 1000.0) / (double) (freq.QuadPart);
    FileTrace (_T ( "********************************************* ************************************ \ n "));
 FileTrace (_T ( "Test result is as follow: \ ntime:% I64x,% .3fms,% .3fms \ n"), (ULONGLONG) 0, Time0, Time1);
 FileTrace (_T ( "********************************************* ************************************ \ n "));
    system ( "pause");
 return 0;
}
     
         
       
         
  More:      
 
- Common Linux System Troubleshooting (Linux)
- Java keyword final, static (Programming)
- Simple to use multi-threaded programming under Linux mutex and condition variable (Programming)
- Getting the Linux shell expr use (Programming)
- Build ftp server under CentOS 6.5 (Server)
- QEMU image file used: qcow2 and raw (Linux)
- OpenvSwitch 2.1.2 shell script to start and stop (Linux)
- Ubuntu: HDF5 error: HDF5 header version does not match with the HDF5 library (Linux)
- Linux operating system Study Notes (Linux)
- CentOS 6.6 installation certification system based on the ftp service (Server)
- iOS persistence of data archiving NSKeyedArchiver (Programming)
- JBPM6 Tutorial - Fast Fun JBPM table (Linux)
- Upgrade installation manual CentOS6.5 GCC4.8.2 (Linux)
- Getting Started with Java NIO (Programming)
- Loop arrays in C language is not easy to find a bug (Programming)
- Some MySQL interview questions (Database)
- Security Features Linux and Unix operating system, programming (Linux)
- Revive Adserver ad server installation on Ubuntu 15.04 / CentOS7 (Server)
- Linux Network Programming --epoll model Detailed principles and examples (Programming)
- The callback function used in C ++ (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.