Advertisement
Guest User

this_thread::get_id() benchmark

a guest
Feb 13th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "Timer.h"
  2. #include <iostream>
  3. #include <thread>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. /*
  9.     Iterations: 10000000
  10.  
  11.     Debug:
  12.         0.325603
  13.         1.27219
  14.  
  15.         0.306712
  16.         1.12284
  17.  
  18.         0.362648
  19.         1.14376
  20.  
  21.         Average:
  22.             0.994963
  23.             3.53879
  24.  
  25.         Subtracted function time:
  26.             2.543827
  27.  
  28.         Time per this_thread::get_id() call: 0.0000002543827
  29.  
  30.  
  31.     Release:
  32.         0.0280782
  33.         0.149169
  34.  
  35.         0.0310837
  36.         0.152756
  37.  
  38.         0.0286644
  39.         0.151138
  40.  
  41.         Average:
  42.             0.0878263
  43.             0.453063
  44.  
  45.         Subtracted function time:
  46.             0.3652367
  47.  
  48.         Time per this_thread::get_id() call: 0.00000003652367
  49. */
  50.  
  51. void doAThing()
  52. {
  53.  
  54. }
  55.  
  56. void doAThing2()
  57. {
  58.     thread::id thing = this_thread::get_id();
  59. }
  60.  
  61. void main()
  62. {
  63.     long long ticksPerSec = Timer.GetTicksPerSecond();
  64.  
  65.     long long start = Timer.GetPreciseUTCTime();
  66.  
  67.     for (int i = 0; i < 10000000; ++i)
  68.     {
  69.         doAThing();
  70.     }
  71.  
  72.     long long end = Timer.GetPreciseUTCTime();
  73.  
  74.  
  75.     long long start2 = Timer.GetPreciseUTCTime();
  76.  
  77.     for (int i = 0; i < 10000000; ++i)
  78.     {
  79.         doAThing2();
  80.     }
  81.  
  82.     long long end2 = Timer.GetPreciseUTCTime();
  83.  
  84.  
  85.     cout << (double)(end - start) / (double)ticksPerSec << "\n" << (double)(end2 - start2) / (double)ticksPerSec;
  86.  
  87.  
  88.     cout << "\n\n";
  89.     system("pause");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement