#include <stdio.h> #ifdef _WIN_ //#ifdef WINVER //#ifdef _WINDOWS_ //#ifdef _WIN32_WINNT /////////////////////// // Windows Timer Code /////////////////////// #include <windows.h> static LARGE_INTEGER liStart, liEnd, liTickPerSec; inline void StartTimer(void) { QueryPerformanceCounter( &liStart); } inline double StopTimer(void) { QueryPerformanceCounter( &liEnd ); QueryPerformanceFrequency( &liTickPerSec); DWORD dwTicks = (DWORD)( liEnd.LowPart - liStart.LowPart ); return (double)dwTicks/(double)liTickPerSec.LowPart; // Seconds } #else //////////////////// // AIX Timer Code //////////////////// //#include <stdlib.h> //#include <stdarg.h> //#include <unistd.h> /* for sleep test */ #include <stdlib.h> #include <sys/time.h> static struct timeval start, end; static struct timezone zone; inline void StartTimer(void) { gettimeofday( &start , &zone ); } inline double StopTimer(void) { gettimeofday( &end , &zone ); return ( ( (double) end.tv_sec + (double) end.tv_usec*1.0e-6 ) -( (double)start.tv_sec + (double)start.tv_usec*1.0e-6 ) );// Seconds } #endif void main() { // Parameters to set int iSize=4; // start size int iMaxSize= 1024*64; // max size double dMinTime = 1.0; int iCount, iTimes, i; double dSec, dSecPerMalloc, dMallocsPerSec; void *v0, *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8, *v9; // StartTimer(); // sleep(3); // dSec = StopTimer(); // printf("dSec, %5.2f\n", dSec ); while( iSize <= iMaxSize ) { iCount = 0; iTimes = 256; do { StartTimer(); for( i = 0 ; i< iTimes ; i++) { ////////////////////////////// // Do 100 Malloc/Free Pairs.. ////////////////////////////// v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); v0 = malloc( iSize ); v1 = malloc( iSize ); v2 = malloc( iSize ); v3 = malloc( iSize ); v4 = malloc( iSize ); v5 = malloc( iSize ); v6 = malloc( iSize ); v7 = malloc( iSize ); v8 = malloc( iSize ); v9 = malloc( iSize ); free( v0 ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); free( v5 ); free( v6 ); free( v7 ); free( v8 ); free( v9 ); /***********************/ } dSec = StopTimer(); iCount += iTimes*100; iTimes += iTimes; // double the number of reps for the next iteration //printf("iSize, %6d, iCount, %5d, dMicroSec, %f\n",iSize,iCount, dMicroSec ); } while ( dSec < dMinTime ); dSecPerMalloc = dSec / (double)iCount; dMallocsPerSec = (double)iCount / dSec; printf("iSize, %6d, iCount, %8d, dSec, %5.2f, Malloc/mSec, %10.0f\n", iSize,iCount, dSec, dMallocsPerSec ); iSize += iSize; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4361 | Dick Dunbar |
Repair Jam build (rule name changes in Jamfile) Submit a starting Test directory |