From fd21c50949e99a978c211c46bc56852460f79bbc Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sat, 15 Nov 2008 02:37:34 +0000 Subject: Clean huffman struct. Replace with local static variables git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@50 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- cleanbench.c | 8 +------- huffman.c | 54 +++++++++++++++++++++++++++++------------------------- nmglobal.h | 32 -------------------------------- 3 files changed, 30 insertions(+), 64 deletions(-) diff --git a/cleanbench.c b/cleanbench.c index 50b2c43..3b17ee7 100644 --- a/cleanbench.c +++ b/cleanbench.c @@ -77,12 +77,6 @@ for (i = 0; i < NUMTESTS; i++) { tests_to_do[i] = TRUE; } -/* -** Initialize test data structures to default -** values. -*/ -global_huffstruct.arraysize=HUFFARRAYSIZE; - puts("BYTEmark* Native Mode Benchmark ver. 2 (10/95)"); puts("Index-split by Andrew D. Balsa (11/97)"); puts("Linux/Unix* port by Uwe F. Mayer (12/96,11/97)"); @@ -90,7 +84,7 @@ puts("\nTEST : Iterations/sec. : Old Index : New Index"); puts(" : : Pentium 90* : AMD K6/233*"); puts("--------------------:------------------:-------------:------------"); -for(i=IDEA;iarraysize); + plaintext = malloc(ARRAY_SIZE * sizeof(char)); if (!plaintext) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); exit(1); } - comparray = malloc(lochuffstruct->arraysize); + comparray = malloc(ARRAY_SIZE * sizeof(char)); if (!comparray) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(plaintext); exit(1); /* FIXME: do I need exits here? */ } - decomparray = malloc(lochuffstruct->arraysize); + decomparray = malloc(ARRAY_SIZE * sizeof(char)); if (!decomparray) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); free(plaintext); @@ -120,9 +124,9 @@ DoHuffman(void) ** added by Uwe F. Mayer */ randnum((int32_t)13); - create_text_block(plaintext,lochuffstruct->arraysize-1,(unsigned short)500); - plaintext[lochuffstruct->arraysize-1L]='\0'; - plaintextlen=lochuffstruct->arraysize; + create_text_block(plaintext,ARRAY_SIZE-1,(unsigned short)500); + plaintext[ARRAY_SIZE-1L]='\0'; + plaintextlen=ARRAY_SIZE; /* ** See if we need to perform self adjustment loop. @@ -134,16 +138,16 @@ DoHuffman(void) ** # of loops and increasing the loop count until we ** get a number of loops that we can use. */ - for (lochuffstruct->loops = 100; lochuffstruct->loops < MAXHUFFLOOPS; lochuffstruct->loops += 10) { - if (DoHuffIteration(plaintext, comparray, decomparray, lochuffstruct->arraysize, lochuffstruct->loops, hufftree) > MINIMUM_TICKS) { + for (; loops < LOOP_MAX; loops += 10) { + if (DoHuffIteration(plaintext, comparray, decomparray, loops, hufftree) > MINIMUM_TICKS) { break; } } } do { - total_time += DoHuffIteration(plaintext, comparray, decomparray, lochuffstruct->arraysize, lochuffstruct->loops, hufftree); - iterations += lochuffstruct->loops; + total_time += DoHuffIteration(plaintext, comparray, decomparray, loops, hufftree); + iterations += loops; } while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC); free(plaintext); @@ -267,7 +271,7 @@ bytessofar+=linelen; ** (c) Decompresses the text and verifies correct decompression */ static clock_t -DoHuffIteration(char *plaintext, char *comparray, char *decomparray, unsigned long arraysize, unsigned long nloops, huff_node *hufftree) +DoHuffIteration(char *plaintext, char *comparray, char *decomparray, unsigned long nloops, huff_node *hufftree) { clock_t start, stop; int i; /* Index */ @@ -299,12 +303,12 @@ for(i=0;i<256;i++) hufftree[i].c=(unsigned char)i; } -for(j=0;j