Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // randomFreeRandomMalloc.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <vector>
- #include <queue>
- #include <chrono>
- #include <iostream>
- using namespace std;
- static size_t timestamp()
- {
- return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
- }
- int main()
- {
- const int times = 100;
- const size_t bytes = 1048576*10;//10 megabytes
- auto start = timestamp();
- //
- queue<unsigned char*> fillMe;
- for (int i = 0 ; i < times; i++)
- {
- auto a = (unsigned char*) malloc(bytes);
- fillMe.push(a);
- }
- for (int i = 0 ; i < times; i++)
- {
- auto a = fillMe.front();
- fillMe.pop();
- free(a);
- }
- auto stop = timestamp();
- cout << (stop - start)/(times*1.0f) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment