[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Hoard alternative malloc



Has anyone every tried to build and use hoard memory allocator with mint? 
I just tested it with linux (1 Ghz, 2018.55 BogoMIPS) and it shows really
 good speed improvements compared to libc malloc: 

* micros = microseconds

libc:

 Test results for test_malloc_255_chunks
Test Runs:               10000
micros Allover:          17305
Average micros per call: 1.730500

 Test results for test_malloc_4096_chunks
Test Runs:               10000
micros Allover:          250020
Average micros per call: 25.002000

 Test results for test_malloc_81920_chunks
Test Runs:               100
micros Allover:          1665
Average micros per call: 16.650000

 Test results for test_free_chunks
Test Runs:               10000
micros Allover:          21375
Average micros per call: 2.137500


Hoard: 

 Test results for test_malloc_255_chunks
Test Runs:               10000
micros Allover:          6619
Average micros per call: 0.661900

 Test results for test_malloc_4096_chunks
Test Runs:               10000
micros Allover:          23601
Average micros per call: 2.360100

 Test results for test_malloc_81920_chunks
Test Runs:               100
micros Allover:          49
Average micros per call: 0.490000

 Test results for test_free_chunks
Test Runs:               10000
micros Allover:          8021
Average micros per call: 0.802100

Or did anyone tested other memory allocators? I found this looks quite
impressing :) 

Test program: 
--------------

#include <sys/time.h> 
#include <stdio.h> 
#include <unistd.h> 
#include <stdlib.h> 

int counts = 10000;
struct timeval start;
struct timeval end;
long mtime, seconds, useconds;

void inline measure(void)
{
	seconds  = end.tv_sec  - start.tv_sec; 
    useconds = end.tv_usec - start.tv_usec; 
	mtime = seconds * 1000000 + useconds; 
}

void inline show(char * title)
{
	printf("\n Test results for %s\n", title );
	printf("Test Runs:               %d\n", counts );
	printf("micros Allover:          %lu\n", mtime );
	printf("Average micros per call: %f\n", (float)mtime/(float)counts );
	
}

#define start() gettimeofday(&start, NULL); 
#define stop(s) gettimeofday(&end, NULL);   measure(); 	show(s);


void test_malloc_255_chunks()
{
	int i = 0;
	char * array[counts];
	start();
	for( i = 0; i < counts; i++)
	{
		array[i]=malloc( 255 );
		if(array[i] == NULL)
		{
			printf("%s: Malloc error!\n", __FUNCTION__);
			break;
		}
	}
	stop( __FUNCTION__ );
	for( i = 0; i < counts; i++)
	{
		if(array[i] != NULL)
		{
			free( array[i] );
		}
	}
}

void test_malloc_4096_chunks()
{
	int i = 0;
	char * array[counts];
	start();
	for( i = 0; i < counts; i++)
	{
		array[i]=malloc( 4096 );
		if(array[i] == NULL)
		{
			printf("%s: Malloc error!\n", __FUNCTION__);
			break;
		}
	}
	stop( __FUNCTION__ );
	for( i = 0; i < counts; i++)
	{
		if(array[i] != NULL)
		{
			free( array[i] );
		}
	}
}

void test_malloc_81920_chunks()
{
	int i = 0;
	int oldcounts = counts;
	counts = 100;
	char * array[counts];
	start();
	for( i = 0; i < counts; i++)
	{
		array[i]=malloc( 4096 );
		if(array[i] == NULL)
		{
			printf("%s: Malloc error!\n", __FUNCTION__);
			break;
		}
	}
	stop( __FUNCTION__ );
	for( i = 0; i < counts; i++)
	{
		if(array[i] != NULL)
		{
			free( array[i] );
		}
	}
	counts = oldcounts;
}

void test_free_chunks()
{
	int i = 0;
	char * array[counts];
	
	for( i = 0; i < counts; i++)
	{
		array[i]=malloc( 4096 );
		if(array[i] == NULL)
		{
			printf("%s: Malloc error!\n", __FUNCTION__);
			break;
		}
	}
	start();
	for( i = 0; i < counts; i++)
	{
		if(array[i] != NULL)
		{
			free( array[i] );
		}
	}
	stop( __FUNCTION__ );
}

int main(int argc, char *argv[] )
{
	test_malloc_255_chunks();
	test_malloc_4096_chunks();
	test_malloc_81920_chunks();
	test_free_chunks();
	printf("\n");
	return 0;
}