8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:03:03 +01:00

Update memory manager tests

This commit is contained in:
skidder 2004-08-22 21:31:19 +00:00
parent 7e79004bd1
commit 933488964a
3 changed files with 53 additions and 58 deletions

View File

@ -24,7 +24,7 @@
* Contributor(s): ______________________________________.
*
*
* $Id: class_perf.cpp,v 1.13 2004-08-10 04:10:47 skidder Exp $
* $Id: class_perf.cpp,v 1.14 2004-08-22 21:31:19 skidder Exp $
*
*/
@ -41,12 +41,12 @@ void start() {
t = clock();
}
const int TEST_ITEMS = 100000;
const int TEST_ITEMS = 5000000;
void report(int scale) {
void report(int scaleNode, int scaleTree) {
clock_t d = clock();
printf("Add+remove %d elements from tree of scale %d took %d milliseconds. \n",
TEST_ITEMS, scale, (int)(d-t)*1000/CLOCKS_PER_SEC);
printf("Add+remove %d elements from tree of scale %d/%d took %d milliseconds. \n",
TEST_ITEMS, scaleNode, scaleTree, (int)(d-t)*1000/CLOCKS_PER_SEC);
}
using namespace Firebird;
@ -66,14 +66,14 @@ static void testTree() {
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 10, 10> tree10(NULL);
DefaultComparator<int>, 30, 30> tree30(NULL);
for (i=0; i<TEST_ITEMS;i++)
tree10.add((*v)[i]);
tree30.add((*v)[i]);
for (i=0; i<TEST_ITEMS;i++) {
if (tree10.locate((*v)[i]))
tree10.fastRemove();
if (tree30.locate((*v)[i]))
tree30.fastRemove();
}
report(10);
report(30, 30);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
@ -84,7 +84,7 @@ static void testTree() {
if (tree50.locate((*v)[i]))
tree50.fastRemove();
}
report(50);
report(50, 50);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
@ -95,7 +95,7 @@ static void testTree() {
if (tree75.locate((*v)[i]))
tree75.fastRemove();
}
report(75);
report(75, 75);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
@ -106,7 +106,18 @@ static void testTree() {
if (tree100.locate((*v)[i]))
tree100.fastRemove();
}
report(100);
report(100, 100);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 100, 250> tree100_250(NULL);
for (i=0; i<TEST_ITEMS;i++)
tree100_250.add((*v)[i]);
for (i=0; i<TEST_ITEMS;i++) {
if (tree100_250.locate((*v)[i]))
tree100_250.fastRemove();
}
report(100, 250);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
@ -117,29 +128,7 @@ static void testTree() {
if (tree200.locate((*v)[i]))
tree200.fastRemove();
}
report(200);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 250, 250> tree250(NULL);
for (i=0; i<TEST_ITEMS;i++)
tree250.add((*v)[i]);
for (i=0; i<TEST_ITEMS;i++) {
if (tree250.locate((*v)[i]))
tree250.fastRemove();
}
report(250);
start();
BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
DefaultComparator<int>, 500, 500> tree500(NULL);
for (i=0; i<TEST_ITEMS;i++)
tree500.add((*v)[i]);
for (i=0; i<TEST_ITEMS;i++) {
if (tree500.locate((*v)[i]))
tree500.fastRemove();
}
report(500);
report(250, 250);
std::set<int> stlTree;
start();
@ -158,7 +147,7 @@ void report() {
printf("Operation took %d milliseconds.\n", (int)(d-t)*1000/CLOCKS_PER_SEC);
}
const int ALLOC_ITEMS = 10000000;
const int ALLOC_ITEMS = 5000000;
const int MAX_ITEM_SIZE = 50;
const int BIG_ITEMS = ALLOC_ITEMS / 10;
const int BIG_SIZE = MAX_ITEM_SIZE * 5;

View File

@ -24,7 +24,7 @@
* Contributor(s): ______________________________________.
*
*
* $Id: class_test.cpp,v 1.19 2004-08-09 01:24:54 skidder Exp $
* $Id: class_test.cpp,v 1.20 2004-08-22 21:31:19 skidder Exp $
*
*/
@ -366,7 +366,7 @@ void testBePlusTree() {
printf(passed ? "PASSED\n" : "FAILED\n");
}
const int ALLOC_ITEMS = 10000;
const int ALLOC_ITEMS = 10000000;
const int MAX_ITEM_SIZE = 50;
const int BIG_ITEMS = ALLOC_ITEMS / 10;
const int BIG_SIZE = MAX_ITEM_SIZE * 5;
@ -374,6 +374,10 @@ const int BIG_SIZE = MAX_ITEM_SIZE * 5;
const int LARGE_ITEMS = 10;
const size_t LARGE_ITEM_SIZE = 300000;
// Use define to be able to disable some of the checks easily
//#define VERIFY_POOL(pool) pool->verify_pool()
#define VERIFY_POOL(pool)
struct AllocItem {
int order;
void *item;
@ -394,22 +398,24 @@ void testAllocator() {
Vector<void*, LARGE_ITEMS> la;
printf("Allocate %d large items: ", LARGE_ITEMS);
int i;
for (i = 0; i<LARGE_ITEMS; i++)
la.add(pool->allocate(LARGE_ITEM_SIZE));
pool->verify_pool();
for (i = 0; i<LARGE_ITEMS; i++) {
la.add(pool->allocate(LARGE_ITEM_SIZE));
VERIFY_POOL(pool);
}
VERIFY_POOL(pool);
printf(" DONE\n");
printf("Allocate %d items: ", ALLOC_ITEMS);
int n = 0;
pool->verify_pool();
VERIFY_POOL(pool);
for (i = 0; i < ALLOC_ITEMS; i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1)};
items.add(temp);
}
printf(" DONE\n");
pool->verify_pool();
parent->verify_pool();
VERIFY_POOL(pool);
VERIFY_POOL(parent);
printf("Deallocate half of items in quasi-random order: ");
n = 0;
@ -418,28 +424,28 @@ void testAllocator() {
n++;
} while (n < ALLOC_ITEMS / 2 && items.getNext());
printf(" DONE\n");
pool->verify_pool();
parent->verify_pool();
VERIFY_POOL(pool);
VERIFY_POOL(parent);
printf("Allocate %d big items: ", BIG_ITEMS);
n = 0;
pool->verify_pool();
VERIFY_POOL(pool);
for (i = 0; i < BIG_ITEMS; i++) {
n = n * 47163 - 57412;
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1)};
bigItems.add(temp);
}
printf(" DONE\n");
pool->verify_pool();
parent->verify_pool();
VERIFY_POOL(pool);
VERIFY_POOL(parent);
printf("Deallocate the rest of small items in quasi-random order: ");
while (items.getNext()) {
pool->deallocate(items.current().item);
}
printf(" DONE\n");
pool->verify_pool();
parent->verify_pool();
VERIFY_POOL(pool);
VERIFY_POOL(parent);
printf("Deallocate big items in quasi-random order: ");
if (bigItems.getFirst()) do {
@ -450,16 +456,16 @@ void testAllocator() {
printf("Deallocate %d large items: ", LARGE_ITEMS/2);
for (i = 0; i<LARGE_ITEMS/2; i++)
pool->deallocate(la[i]);
pool->verify_pool();
VERIFY_POOL(pool);
printf(" DONE\n");
pool->verify_pool();
parent->verify_pool();
// pool->verify_pool();
// parent->verify_pool();
pool->print_contents(stdout, false);
parent->print_contents(stdout, false);
MemoryPool::deletePool(pool);
parent->verify_pool();
// parent->verify_pool();
// TODO:
// Test critically low memory conditions
// Test that tree correctly recovers in low-memory conditions

View File

@ -2,13 +2,13 @@
# this should be compiled with optimization turned off and with NDEBUG undefined
ulimit -s unlimited
ulimit -c unlimited
#g++ -ggdb -Wall -I../../include -DTESTING_ONLY -DUSE_VALGRIND class_test.cpp alloc.cpp ../fb_exception.cpp 2> aa
#g++ -ggdb -Wall -I../../include -DTESTING_ONLY -DDEBUG_GDS_ALLOC class_test.cpp alloc.cpp ../fb_exception.cpp 2> aa
#valgrind --tool=memcheck ./a.out
#export LD_LIBRARY_PATH=/usr/local/lib64
# Chose the best algorithm parameters for the target architecture
#/usr/local/bin/
g++ -O3 -DHAVE_STDLIB_H -DNDEBUG -DTESTING_ONLY \
g++ -ggdb -O3 -DHAVE_STDLIB_H -DNDEBUG -DTESTING_ONLY \
-I../../include class_perf.cpp alloc.cpp ../fb_exception.cpp 2> aa
./a.out