[ create a new paste ] login | about

Link: http://codepad.org/20UvKEhT    [ raw code | output | fork ]

manuelj_pg - C++, pasted on Feb 15:
#include <ctime>
#include <iostream>
#include <vector>
#include <memory>
#include <cmath>

double new_object(int N)
{
  int const reps = int(1000000 / sqrt(double(N)));
  
  std::vector<char*> ptrs(reps);
  std::clock_t const start = std::clock();
  for(int i = 0; i < reps; ++i)
     ptrs[i] = new char[N];
  std::clock_t const end = std::clock(); 
  for(int i = 0; i < reps; ++i)
     delete ptrs[i];
  return double(end - start) / reps / CLOCKS_PER_SEC * 1e6;
}

int main()
{
    for(int i = 1; i < 500000; i *= 2) 
        std::cout << "Cost of allocating " << i << " chars: " << new_object(i) << " microseconds\n";
}


Output:
1
Timeout


Create a new paste based on this one


Comments: