Skip to content

Instantly share code, notes, and snippets.

@fenbf
Created July 22, 2015 10:35
Show Gist options
  • Save fenbf/699be84a533d2e495ea4 to your computer and use it in GitHub Desktop.
Save fenbf/699be84a533d2e495ea4 to your computer and use it in GitHub Desktop.
// simple perf test for memory allocations
// bfilipek.com
#include <iostream>
#include <memory>
#include <vector>
#include <chrono>
int main()
{
const int NUM_ELEMENTS = 100000;
const int NUM_ITERS = 100;
const int NUM_ALLOC = 100;
//_asm int 3
std::cout << std::hex;
auto startTime = std::chrono::system_clock::now();
for (int iter = 0; iter < NUM_ITERS; ++iter)
{
for (int allocCount = 0; allocCount < NUM_ALLOC; ++allocCount)
{
std::vector<int> testVec(NUM_ELEMENTS);
std::unique_ptr<int[]> pTestMem(new int[NUM_ELEMENTS]);
if (iter % 10 == 0 && allocCount == 0)
std::cout << "pTestMem: " << pTestMem[0] << ", testVec: " << testVec[0] << std::endl;
}
}
auto endTime = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
std::cout << std::dec;
std::cout << elapsed.count() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment