Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BlogBenchmarks.cpp : Defines the entry point for the console application.
- //
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- #include <vector>
- #include <list>
- #include <utility>
- #include <string>
- using namespace std;
- struct benchmark
- {
- benchmark(const wchar_t* message)
- : m_msg(message)
- {
- m_start = time(NULL);
- std::wcout << m_msg << L" started" << std::endl;
- }
- ~benchmark()
- {
- std::wcout << m_msg << L": " << time(NULL) - m_start << L" sec" << std::endl;
- }
- time_t m_start;
- const wchar_t* m_msg;
- };
- const size_t totalSize = 100000000; // 100 million bytes
- void allocs_1()
- {
- for (int i = 0; i < totalSize / 4; i++)
- new int;
- }
- void allocs_2()
- {
- for (int i = 0; i < totalSize / 40; i++)
- new int[10];
- }
- void allocs_3()
- {
- for (int i = 0; i < totalSize / 400; i++)
- new int[100];
- }
- void allocs_4()
- {
- for (int i = 0; i < totalSize / 4000; i++)
- new int[1000];
- }
- void allocs_5()
- {
- for (int i = 0; i < totalSize / 40000; i++)
- new int[10000];
- }
- int main(int argc, char* argv[])
- {
- std::string dummy;
- std::wcout << L"Press Enter to start" << std::endl;
- std::getline(std::cin, dummy);
- allocs_1();
- std::wcout << L"Allocs 1 completed" << std::endl;
- std::getline(std::cin, dummy);
- allocs_2();
- std::wcout << L"Allocs 2 completed" << std::endl;
- std::getline(std::cin, dummy);
- allocs_3();
- std::wcout << L"Allocs 3 completed" << std::endl;
- std::getline(std::cin, dummy);
- allocs_4();
- std::wcout << L"Allocs 4 completed" << std::endl;
- std::getline(std::cin, dummy);
- allocs_5();
- std::wcout << L"Allocs 5 completed" << std::endl;
- std::getline(std::cin, dummy);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement