rendered paste body#include "pch.h"#define NOMINMAX#include <iostream>#include <string>#include <sstream>#include <limits>#include <vector>#include <list>#include <map>#include <stdio.h>#include "Windows.h"#pragma comment(lib, "Winmm.lib")using namespace std;#define STRING//#define STRING_C// STRING_C not yet implemented... I hate char*...#ifdef STRING#ifdef STRING_Cconst int IMAX = numeric_limits<int>::max() / 200; // #elseconst int IMAX = numeric_limits<int>::max() / 200; // 1000 is about the same time as 200 for C#...#endif#elseconst int IMAX = numeric_limits<int>::max() / 200; // 100 is the limit on my machine (Core2Duo, 2GB ram), 200 in C##endifint main(){#ifdef STRING#ifdef STRING_C cout << "C++ Working with " << IMAX << " string values, C-style.\n" << endl;#else cout << "C++ Working with " << IMAX << " string values, C++-style.\n" << endl;#endif#else cout << "C++ Working with " << IMAX << " double values.\n" << endl;#endif timeBeginPeriod(1); double value; unsigned long resultTime; unsigned long startTime; ostringstream strstream;#ifdef STRING string tvalue;#else double tvalue;#endif #pragma region vector benchmarks {#ifdef STRING vector<string> list;#else vector<double> list;#endif cout << "vector growing at the end" << endl; startTime = timeGetTime(); for (int i = IMAX; i >= 0; i--) { value = i % 100 * i / 100;#ifdef STRING#ifdef STRING_C#else strstream << value; list.push_back(strstream.str()); strstream.str("");#endif#else list.push_back(value);#endif } resultTime = timeGetTime() - startTime; cout << " inserts:\t " << resultTime << " ms" << endl; startTime = timeGetTime(); for (int i = 0; i < IMAX; i++) { tvalue = list[i]; } resultTime = timeGetTime() - startTime; cout << " reads:\t\t " << resultTime << " ms" << endl; } #pragma endregion cout << endl; #pragma region Hashtable benchmarks { //Dictionary<int, string> dict = new Dictionary<int, string>();#ifdef STRING map<int, string> dict;#else map<int, double> dict;#endif cout << "map" << endl; startTime = timeGetTime(); for (int i = IMAX; i >= 0; i--) { value = i % 100 * i / 100;#ifdef STRING strstream << value; dict[i] = strstream.str(); strstream.str("");#else dict[i] = value;#endif } resultTime = timeGetTime() - startTime; cout << " inserts:\t " << resultTime << " ms" << endl; startTime = timeGetTime(); for (int i = 0; i < IMAX; i++) { tvalue = dict[i]; } resultTime = timeGetTime() - startTime; cout << " reads:\t\t " << resultTime << " ms" << endl; } #pragma endregion cout << endl; #pragma region list benchmarks {#ifdef STRING list<string> list;#else list<double> list;#endif cout << "list" << endl; startTime = timeGetTime(); for (int i = IMAX; i >= 0; i--) { value = i % 100 * i / 100;#ifdef STRING strstream << value; list.push_front(strstream.str()); strstream.str("");#else list.push_front(value);#endif } resultTime = timeGetTime() - startTime; cout << " inserts:\t " << resultTime << " ms" << endl; startTime = timeGetTime();#ifdef STRING std::list<string>::iterator it#else std::list<double>::iterator it#endif = list.begin(); while(it != list.end()) { tvalue = *it; it++; //tvalue = enumerator.Current; } resultTime = timeGetTime() - startTime; cout << " reads:\t\t " << resultTime << " ms (sequence)" << endl; } #pragma endregion cout << endl; #pragma region vector benchmarks {#ifdef STRING vector<string> list;#else vector<double> list;#endif cout << "vector inserting at beginning (press ctrl+c to cancel - this takes ages)" << endl; startTime = timeGetTime(); for (int i = IMAX; i >= 0; i--) { value = i % 100 * i / 100; //list.Insert(0, value.ToString());#ifdef STRING strstream << value; list.insert(list.begin(), strstream.str()); strstream.str("");#else list.insert(list.begin(), value);#endif //if (i % 10000 == 0) // cout << ((1 - ((double)i / (double)IMAX)) * 100) << "\r" << flush; } resultTime = timeGetTime() - startTime; cout << " inserts:\t " << resultTime << " ms" << endl; startTime = timeGetTime(); for (int i = 0; i < IMAX; i++) { tvalue = list[i]; } resultTime = timeGetTime() - startTime; cout << " reads:\t\t " << resultTime << " ms" << endl; } #pragma endregion timeEndPeriod(1); return 0;}