29 #define _CRT_SECURE_NO_WARNINGS
30 #define _CRT_SECURE_NO_DEPRECATE // VS2005
33 #if (defined(__sun__) && (!defined(__LP64__))) // Sun Solaris 32-bits requires specific definitions
34 # define _LARGEFILE_SOURCE
35 # define FILE_OFFSET_BITS=64
36 #elif ! defined(__LP64__) // No point defining Large file for 64 bit
37 # define _LARGEFILE64_SOURCE
42 # define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
43 # define BMK_LEGACY_TIMER 1
48 # define _rotl(x,r) ((x << r) | (x >> (32 - r)))
57 #include <sys/types.h>
61 #if defined(BMK_LEGACY_TIMER)
62 # include <sys/timeb.h>
64 # include <sys/time.h>
68 #define COMPRESSOR0 LZ4_compress
70 #define COMPRESSOR1 LZ4_compressHC
71 #define DEFAULTCOMPRESSOR LZ4_compress
78 #if defined(_MSC_VER) // Visual Studio does not support 'stdint' natively
79 #define BYTE unsigned __int8
80 #define U16 unsigned __int16
81 #define U32 unsigned __int32
83 #define U64 unsigned __int64
100 #define KNUTH 2654435761U
101 #define MAX_MEM (1984<<20)
102 #define DEFAULT_CHUNKSIZE (8<<20)
127 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
159 #if defined(BMK_LEGACY_TIMER)
169 nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);
181 gettimeofday(&tv,
NULL);
182 nCount = (int) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000);
193 nSpan += 0x100000 * 1000;
200 const BYTE* data = (
const BYTE*)buff;
201 const int nblocks = length >> 2;
207 const U32* blocks = (
const U32*)(data + nblocks*4);
210 for(i = -nblocks; i; i++)
220 h1 = h1*5+0xe6546b64;
224 const BYTE* tail = (
const BYTE*)(data + nblocks*4);
229 case 3: k1 ^= tail[2] << 16;
230 case 2: k1 ^= tail[1] << 8;
231 case 1: k1 ^= tail[0];
232 k1 *= c1; k1 =
_rotl(k1,15); k1 *= c2; h1 ^= k1;
249 size_t step = (64U<<20);
252 requiredMem = (((requiredMem >> 25) + 1) << 26);
255 requiredMem += 2*step;
259 testmem = malloc ((
size_t)requiredMem);
263 return (
size_t) (requiredMem - step);
270 #if defined(_MSC_VER)
271 struct _stat64 statbuf;
272 r = _stat64(infilename, &statbuf);
275 r = stat(infilename, &statbuf);
277 if (r || !S_ISREG(statbuf.st_mode))
return 0;
278 return (
U64)statbuf.st_size;
297 char* out_buff;
int out_buff_size;
322 while (fileIdx<nbFiles)
325 infilename = fileNamesTable[fileIdx++];
326 fileIn = fopen( infilename,
"rb" );
329 DISPLAY(
"Pb opening %s\n", infilename);
336 if ((
U64)benchedsize > largefilesize) benchedsize = (
size_t)largefilesize;
337 if (benchedsize < largefilesize)
339 DISPLAY(
"Not enough memory for '%s' full size; testing %i MB only...\n", infilename, (
int)(benchedsize>>20));
344 in_buff = malloc((
size_t )benchedsize);
345 nbChunks = (int) (benchedsize /
chunkSize) + 1;
347 out_buff_size = nbChunks * maxCChunkSize;
348 out_buff = malloc((
size_t )out_buff_size);
351 if(!in_buff || !out_buff)
353 DISPLAY(
"\nError: not enough memory!\n");
363 size_t remaining = benchedsize;
365 char* out = out_buff;
366 for (i=0; i<nbChunks; i++)
377 DISPLAY(
"Loading %s... \r", infilename);
378 readSize = fread(in_buff, 1, benchedsize, fileIn);
381 if(readSize != benchedsize)
383 DISPLAY(
"\nError: problem reading file '%s' !! \n", infilename);
395 int loopNb, nb_loops, chunkNb;
398 double fastestC = 100000000., fastestD = 100000000.;
405 DISPLAY(
"%1i-%-14.14s : %9i ->\r", loopNb, infilename, (
int)benchedsize);
406 {
size_t i;
for (i=0; i<benchedsize; i++) out_buff[i]=(
char)i; }
414 for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
420 if ((
double)milliTime < fastestC*nb_loops) fastestC = (double)milliTime/nb_loops;
421 cSize=0;
for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += chunkP[chunkNb].
outputSize;
422 ratio = (double)cSize/(
double)benchedsize*100.;
424 DISPLAY(
"%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s\r", loopNb, infilename, (
int)benchedsize, (
int)cSize, ratio, (
double)benchedsize / fastestC / 1000.);
427 {
size_t i;
for (i=0; i<benchedsize; i++) in_buff[i]=0; }
435 for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
442 if ((
double)milliTime < fastestD*nb_loops) fastestD = (double)milliTime/nb_loops;
443 DISPLAY(
"%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\r", loopNb, infilename, (
int)benchedsize, (
int)cSize, ratio, (
double)benchedsize / fastestC / 1000., (
double)benchedsize / fastestD / 1000.);
447 if (crcc!=crcd) {
DISPLAY(
"\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", infilename, (
unsigned)crcc, (
unsigned)crcd);
break; }
453 DISPLAY(
"%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\n", infilename, (
int)benchedsize, (
int)cSize, ratio, (
double)benchedsize / fastestC / 1000., (
double)benchedsize / fastestD / 1000.);
455 DISPLAY(
"%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n", infilename, (
int)benchedsize, (
int)cSize, ratio, (
double)benchedsize / fastestC / 1000., (
double)benchedsize / fastestD / 1000.);
457 totals += benchedsize;
469 printf(
"%-16.16s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n",
" TOTAL", (
long long unsigned int)totals, (
long long unsigned int)totalz, (
double)totalz/(
double)totals*100., (
double)totals/totalc/1000., (
double)totals/totald/1000.);
471 if (
BMK_pause) { printf(
"press enter...\n"); getchar(); }