1 Star 0 Fork 0

Mouri_Naruto / nedmalloc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
make_pgos.c 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
/* make_pgos.c
Simply runs through each of the most common code paths for PGO purposes
(C) 2010 Niall Douglas
*/
#define _CRT_SECURE_NO_WARNINGS 1 /* Don't care about MSVC warnings on POSIX functions */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "nedmalloc.h"
#define RECORDS 100000
static void run(size_t maxsize, size_t records, size_t loops)
{
int n,m;
static void *mem[RECORDS];
for(m=0; m<loops; m++)
{
for(n=0; n<records-1; n++)
{
static int reallocflip;
int dorealloc=(reallocflip=!reallocflip);
size_t size=rand() & (maxsize-1);
if(!mem[n])
mem[n]=nedmalloc(size);
else if(n>0 && dorealloc)
mem[n-1]=nedrealloc(mem[n-1], size);
else if(n>1)
{
nedfree(mem[n-2]);
mem[n-2]=0;
}
}
}
for(n=0; n<records; n++)
{
if(mem[n])
{
nedfree(mem[n]);
mem[n]=0;
}
}
}
int main(void)
{
printf("nedmalloc PGO maker\n"
"-=-=-=-=-=-=-=-=-=-\n");
printf("Small allocations\n");
run(8192, RECORDS, 10);
printf("Medium allocations\n");
run(256*1024, RECORDS/100, 1000);
printf("Large allocations\n");
run(8*1024*1024, RECORDS/1000, 10000);
return 0;
}
1
https://gitee.com/Mouri_Naruto/nedmalloc.git
git@gitee.com:Mouri_Naruto/nedmalloc.git
Mouri_Naruto
nedmalloc
nedmalloc
master

搜索帮助