/* * PROGRAM: Client/Server Common Code * MODULE: class_perf.cpp * DESCRIPTION: Class library performance measurements * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * You may obtain a copy of the Licence at * http://www.gnu.org/licences/lgpl.html * * As a special exception this file can also be included in modules * with other source code as long as that source code has been * released under an Open Source Initiative certificed licence. * More information about OSI certification can be found at: * http://www.opensource.org * * This module is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public Licence for more details. * * This module was created by members of the firebird development * team. All individual contributions remain the Copyright (C) of * those individuals and all rights are reserved. Contributors to * this file are either listed below or can be obtained from a CVS * history command. * * Created by: Nickolay Samofatov * * Contributor(s): * * * $Id: class_perf.cpp,v 1.11 2004-05-21 06:14:51 robocop Exp $ * */ #include "tree.h" #include "alloc.h" //#include "../memory/memory_pool.h" #include #include #include clock_t t; void start() { t = clock(); } const int TEST_ITEMS = 10000000; void report(int scale) { 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); } using namespace Firebird; static void testTree() { printf("Fill array with test data (%d items)...", TEST_ITEMS); Vector *v = new Vector(); int n = 0; int i; for (i=0;iadd(((i+n) % TEST_ITEMS + TEST_ITEMS)/2); } printf(" DONE\n"); MallocAllocator temp; start(); BePlusTree, DefaultComparator, 10, 10> tree10(NULL); for (i=0; i, DefaultComparator, 50, 50> tree50(NULL); for (i=0; i, DefaultComparator, 75, 75> tree75(NULL); for (i=0; i, DefaultComparator, 100, 100> tree100(NULL); for (i=0; i, DefaultComparator, 200, 200> tree200(NULL); for (i=0; i, DefaultComparator, 250, 250> tree250(NULL); for (i=0; i, DefaultComparator, 500, 500> tree500(NULL); for (i=0; i stlTree; start(); for (i=0; i i2.order || (i1.order==i2.order && i1.item > i2.item); } }; static void testAllocatorOverhead() { printf("Calculating measurement overhead...\n"); start(); MallocAllocator allocator; BePlusTree,AllocItem> items(&allocator), bigItems(&allocator); // Allocate small items int n = 0; int i; for (i=0;i,AllocItem> items(&allocator), bigItems(&allocator); // Allocate small items int i, n = 0; for (i=0;iallocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)}; items.add(temp); } // Deallocate half of small items n = 0; if (items.getFirst()) do { pool->deallocate(items.current().item); n++; } while (n < ALLOC_ITEMS/2 && items.getNext()); // Allocate big items for (i=0;iallocate((n % BIG_SIZE + BIG_SIZE)/2+1)}; bigItems.add(temp); } // Deallocate the rest of small items while (items.getNext()) { pool->deallocate(items.current().item); } // Deallocate big items if (bigItems.getFirst()) do { pool->deallocate(bigItems.current().item); } while (bigItems.getNext()); Firebird::MemoryPool::deletePool(pool); report(); } static void testAllocatorMalloc() { printf("Test reference run for ::malloc...\n"); start(); MallocAllocator allocator; BePlusTree,AllocItem> items(&allocator), bigItems(&allocator); // Allocate small items int i, n = 0; for (i=0;i,AllocItem> items(&allocator), bigItems(&allocator); // Allocate small items int n = 0; int i; for (i=0;iallocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1,0)}; items.add(temp); } // Deallocate half of small items n = 0; if (items.getFirst()) do { pool->deallocate(items.current().item); n++; } while (n < ALLOC_ITEMS/2 && items.getNext()); // Allocate big items for (i=0;iallocate((n % BIG_SIZE + BIG_SIZE)/2+1,0)}; bigItems.add(temp); } // Deallocate the rest of small items while (items.getNext()) { pool->deallocate(items.current().item); } // Deallocate big items if (bigItems.getFirst()) do { pool->deallocate(bigItems.current().item); } while (bigItems.getNext()); delete pool; report(); }*/ int main() { testTree(); testAllocatorOverhead(); testAllocatorMemoryPool(); testAllocatorMalloc(); // testAllocatorOldPool(); }