summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
Diffstat (limited to 'programs')
-rw-r--r--programs/bench.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/programs/bench.c b/programs/bench.c
index 51c07f5..33f5fcf 100644
--- a/programs/bench.c
+++ b/programs/bench.c
@@ -353,22 +353,28 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
static size_t BMK_findMaxMem(U64 requiredMem)
{
- size_t const step = 64 MB;
- BYTE* testmem = NULL;
+ size_t step = 64 MB;
+ BYTE* testmem=NULL;
requiredMem = (((requiredMem >> 26) + 1) << 26);
- requiredMem += step;
+ requiredMem += 2*step;
if (requiredMem > maxMemory) requiredMem = maxMemory;
- do {
- testmem = (BYTE*)malloc((size_t)requiredMem);
- requiredMem -= step;
- } while (!testmem);
+ while (!testmem) {
+ if (requiredMem > step) requiredMem -= step;
+ else requiredMem >>= 1;
+ testmem = (BYTE*) malloc ((size_t)requiredMem);
+ }
+ free (testmem);
+
+ /* keep some space available */
+ if (requiredMem > step) requiredMem -= step;
+ else requiredMem >>= 1;
- free(testmem);
- return (size_t)(requiredMem);
+ return (size_t)requiredMem;
}
+
static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize,
const char* displayName, int cLevel, int cLevelLast,
const size_t* fileSizes, unsigned nbFiles)