Advertisement
Guest User

Untitled

a guest
Jul 5th, 2010
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. // it.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <list>
  7. #include "windows.h"
  8. #include <vector>
  9. #include <map>
  10.  
  11. using namespace std;
  12.  
  13. struct custom_t
  14. {
  15.     int a;
  16.     float b;
  17.     char c;
  18. };
  19.  
  20. int _tmain(int argc, _TCHAR* argv[])
  21. {
  22.     __int64 ctr1 = 0, ctr2 = 0, freq = 0;
  23.     double res[20];
  24.  
  25.  
  26.     QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
  27.  
  28.     vector<custom_t> vcustom;
  29.     list<custom_t> lcustom;
  30.     map<int, custom_t> mcustom;
  31.  
  32.     for (unsigned int x = 0; x < 10000000;x++)
  33.     {
  34.         custom_t xx;
  35.         vcustom.push_back(xx);
  36.         lcustom.push_back(xx);
  37.         mcustom[x] = xx;
  38.     }
  39.  
  40.     // vector
  41.     for (int k=0; k<20; ++k)
  42.     {
  43.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  44.  
  45.         for (vector<custom_t>::iterator i = vcustom.begin(); i != vcustom.end();++i)
  46.         {
  47.             (*i).a++;
  48.         }
  49.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  50.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  51.     }
  52.  
  53.     double fin = 0.0;
  54.     for (int i=0; i<20; ++i)
  55.         fin += res[i];
  56.  
  57.     fin /= 20.0;
  58.     printf(">>> AVG vector<custom_t> ++it Time: %f\n", fin);
  59.  
  60.     for (int k=0; k<20; ++k)
  61.     {
  62.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  63.  
  64.         for (vector<custom_t>::iterator i = vcustom.begin(); i != vcustom.end();i++)
  65.         {
  66.             (*i).a++;
  67.         }
  68.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  69.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  70.     }
  71.  
  72.     fin = 0.0;
  73.     for (int i=0; i<20; ++i)
  74.         fin += res[i];
  75.  
  76.     fin /= 20.0;
  77.     printf(">>> AVG vector<custom_t> it++ Time: %f\n", fin);
  78.  
  79.     // list
  80.     for (int k=0; k<20; ++k)
  81.     {
  82.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  83.  
  84.         for (list<custom_t>::iterator i = lcustom.begin(); i != lcustom.end();++i)
  85.         {
  86.             (*i).a++;
  87.         }
  88.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  89.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  90.     }
  91.  
  92.     fin = 0.0;
  93.     for (int i=0; i<20; ++i)
  94.         fin += res[i];
  95.  
  96.     fin /= 20.0;
  97.     printf(">>> AVG list<custom_t> ++it Time: %f\n", fin);
  98.  
  99.  
  100.     for (int k=0; k<20; ++k)
  101.     {
  102.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  103.  
  104.         for (list<custom_t>::iterator i = lcustom.begin(); i != lcustom.end();i++)
  105.         {
  106.             (*i).a++;
  107.         }
  108.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  109.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  110.     }
  111.  
  112.     fin = 0.0;
  113.     for (int i=0; i<20; ++i)
  114.         fin += res[i];
  115.  
  116.     fin /= 20.0;
  117.     printf(">>> AVG list<custom_t> it++ Time: %f\n", fin);
  118.  
  119.     // map
  120.     for (int k=0; k<20; ++k)
  121.     {
  122.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  123.  
  124.         for (map<int, custom_t>::iterator i = mcustom.begin(); i != mcustom.end();++i)
  125.         {
  126.             (*i).second.a++;
  127.         }
  128.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  129.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  130.     }
  131.  
  132.     fin = 0.0;
  133.     for (int i=0; i<20; ++i)
  134.         fin += res[i];
  135.  
  136.     fin /= 20.0;
  137.     printf(">>> AVG map<int, custom_t> ++it Time: %f\n", fin);
  138.  
  139.     for (int k=0; k<20; ++k)
  140.     {
  141.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr1);
  142.  
  143.         for (map<int, custom_t>::iterator i = mcustom.begin(); i != mcustom.end();i++)
  144.         {
  145.             (*i).second.a++;
  146.         }
  147.         QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
  148.         res[k] = (ctr2 - ctr1) * 1.0 / freq;
  149.     }
  150.  
  151.     fin = 0.0;
  152.     for (int i=0; i<20; ++i)
  153.         fin += res[i];
  154.  
  155.     fin /= 20.0;
  156.     printf(">>> AVG map<int, custom_t> i++ Time: %f\n", fin);
  157.  
  158.     return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement