乙個測試ACE各種記憶體分配策略效率的程式

2021-04-15 02:38:39 字數 1672 閱讀 8732

在256m記憶體的redhat9虛擬機器上執行申請釋放10000000,每次大小為1k,結果如下:

testmalloc loop 10000 use time 32.950000 s

testcached loop 10000 use time 1.730000 s

testmallocmmap loop 10000 use time 5.050000 s

testmallocmmaplite loop 10000 use time 5.030000 s

testmalloclocal loop 10000 use time 0.620000 s

testmalloclocalmutex loop 10000 use time 4.250000 s

testmalloc_brk_mutex loop 10000 use time 0.600000 s

testmallocsharemutex loop 10000 use time 4.360000 s

#include "ace/os_ns_stdio.h"

#include "ace/os_ns_string.h"

#include "ace/malloc_t.h"

#include "ace/null_mutex.h"

#include "time.h"

#include "assert.h"

clock_t _begin;

clock_t _end;

int _loop;

#define begin(n) /

_begin = clock(); /

for (_loop = 0; _loop < n; _loop++)           /

_end = clock(); /

printf("%s loop %d use time %lf s/n", s, _loop ,  (double)(_end - _begin) / (double)clocks_per_sec);

const int maxsize = 1024;

void *p[1000];

void testmalloc()

for (i = 0; i < 1000; i++)}

typedef char block[maxsize];

typedef ace_dynamic_cached_allocatorallocator;

allocator cache(1000, maxsize);

void testcached()

for (i = 0; i < 1000; i++)}

typedef ace_mallocmalloc_mmap;

typedef ace_mallocmalloc_local;

typedef ace_mallocmalloc_local_mutex;

typedef ace_mallocmalloc_share_mutex;

typedef ace_mallocmalloc_sbrk_mutex;

typedef ace_mallocmalloc_mmap_lite;

template

void testmalloc(t &ml)

for (i = 0; i < 1000; i++)}

int main(int argc,char* argv)

乙個測試ACE各種記憶體分配策略效率的程式

在256m記憶體的redhat9虛擬機器上執行申請釋放10000000,每次大小為1k,結果如下 testmalloc loop 10000 use time 32.950000 s testcached loop 10000 use time 1.730000 s testmallocmmap l...

ACE記憶體分配器一

ace的記憶體分配器都是支援ace allocator介面。the definition of this class is located in malloc.cpp.class ace allocator brief inte ce for a dynamic memory allocator t...

第乙個ACE測試例子

第乙個ace測試例子 下面的乙個測試例子在linux和windows下均通過,無需改動,只需重新編譯就可達到跨平台執行。從乙個側面反應了ace在可移植性上的魅力。ace 版本 5.6 編譯環境 linux version 2.6.18 4 686 debian 2.6.18.dfsg.1 12 gc...