tstCompressionBenchmark.cpp revision 8437ae69b1ead5e77c1ebcf454d69985d6d5e7f4
/* $Id$ */
/** @file
* Compression Benchmark for SSM and PGM.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Buffer for the decompressed data (g_cbPages). */
static uint8_t *g_pabDecompr;
/** Buffer for the compressed data (g_cbComprAlloc). */
static uint8_t *g_pabCompr;
/** The current size of the compressed data, ComprOutCallback */
/** The current offset into the compressed data, DecomprInCallback. */
static size_t g_offComprIn;
/** The amount of space allocated for compressed data. */
static size_t g_cbComprAlloc;
/**
* Store compressed data in the g_pabCompr buffer.
*/
{
return VINF_SUCCESS;
}
/**
* Read compressed data from g_pabComrp.
*/
{
if (pcbBuf)
// AssertReturn(cb > 0, VERR_EOF);
g_offComprIn += cb;
return VINF_SUCCESS;
}
/**
* Benchmark RTCrc routines potentially relevant for SSM or PGM - All in one go.
*
* @param pabSrc Pointer to the test data.
* @param cbSrc The size of the test data.
*/
{
RTPrintf("Algorithm Speed Time Digest\n"
"------------------------------------------------------------------------------\n");
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
char szDigest[257];
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
}
/**
* Benchmark RTCrc routines potentially relevant for SSM or PGM - Page by page.
*
* @param pabSrc Pointer to the test data.
* @param cbSrc The size of the test data.
*/
{
RTPrintf("Algorithm Speed Time \n"
"----------------------------------------------\n");
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
NanoTS = RTTimeNanoTS();
}
/** Prints an error message and returns 1 for quick return from main use. */
{
return 1;
}
{
RTR3Init();
/*
* Parse arguments.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
const char *pszPageFile = NULL;
uint64_t offPageFile = 0;
{
switch (rc)
{
case 'n':
return Error("The specified page count is too high: %#x (%#llx bytes)\n", g_cPages, (uint64_t)g_cPages * PAGE_SHIFT);
if (g_cPages < 1)
break;
case 'i':
if (cIterations < 1)
return Error("The number of iterations must be 1 or higher\n");
break;
case 'c':
break;
case 'f':
break;
case 'o':
break;
case 'O':
break;
case 'h':
RTPrintf("syntax: tstCompressionBenchmark [options]\n"
"\n"
"Options:\n"
" -h, --help\n"
" Show this help page\n"
" -i, --interations <num>\n"
" The number of iterations.\n"
" -n, --num-pages <pages>\n"
" The number of pages.\n"
" -c, --pages-at-a-time <pages>\n"
" Number of pages at a time.\n"
" -f, --page-file <filename>\n"
" File or device to read the page from. The default\n"
" is to generate some garbage.\n"
" -o, --offset <file-offset>\n"
" Offset into the page file to start reading at.\n");
return 0;
default:
if (rc == VINF_GETOPT_NOT_OPTION)
else if (rc > 0)
{
if (RT_C_IS_GRAPH(rc))
else
}
else if (rc == VERR_GETOPT_UNKNOWN_OPTION)
else
return 1;
}
}
return Error("cPages * cIterations -> overflow\n");
/*
* Gather the test memory.
*/
if (pszPageFile)
{
rc = RTFileReadAllEx(pszPageFile, offPageFile, g_cbPages, RTFILE_RDALL_O_DENY_NONE, (void **)&g_pabSrc, &cbFile);
if (RT_FAILURE(rc))
return Error("Error reading %zu bytes from %s at %llu: %Rrc\n", g_cbPages, pszPageFile, offPageFile, rc);
return Error("Error reading %zu bytes from %s at %llu: got %zu bytes\n", g_cbPages, pszPageFile, offPageFile, cbFile);
}
else
{
if (g_pabSrc)
{
/* Just fill it with something - warn about the low quality of the something. */
RTPrintf("tstCompressionBenchmark: WARNING! No input file was specified so the source\n"
"buffer will be filled with generated data of questionable quality.\n");
#ifdef RT_OS_LINUX
#endif
{
char szTmp[17];
}
}
}
/*
* Double loop compressing and uncompressing the data, where the outer does
* the specified number of interations while the inner applies the different
* compression algorithms.
*/
struct
{
/** The time spent decompressing. */
/** The time spent compressing. */
/** The size of the compressed data. */
/** First error. */
int rc;
/** The compression style: block or stream. */
bool fBlock;
/** Compresstion type. */
/** Compresison level. */
/** Method name. */
const char *pszName;
} aTests[] =
{
/* { 0, 0, 0, VINF_SUCCESS, false, RTZIPTYPE_ZLIB, RTZIPLEVEL_DEFAULT, "RTZip/zlib" }, - slow plus it randomly hits VERR_GENERAL_FAILURE atm. */
};
RTPrintf("tstCompressionBenchmark: TESTING..");
for (uint32_t i = 0; i < cIterations; i++)
{
{
continue;
g_cbCompr = 0;
g_offComprIn = 0;
/*
* Compress it.
*/
{
{
if (RT_FAILURE(rc))
{
break;
}
}
if (RT_FAILURE(rc))
continue;
}
else
{
if (RT_FAILURE(rc))
{
continue;
}
{
if (RT_FAILURE(rc))
{
break;
}
}
if (RT_FAILURE(rc))
continue;
if (RT_FAILURE(rc))
{
break;
}
}
/*
* Decompress it.
*/
NanoTS = RTTimeNanoTS();
{
{
if (RT_FAILURE(rc))
{
break;
}
}
if (RT_FAILURE(rc))
continue;
}
else
{
if (RT_FAILURE(rc))
{
continue;
}
{
if (RT_FAILURE(rc))
{
break;
}
}
if (RT_FAILURE(rc))
continue;
}
{
continue;
}
}
}
if (RT_SUCCESS(rc))
RTPrintf("\n");
/*
* Report the results.
*/
rc = 0;
RTPrintf("tstCompressionBenchmark: BEGIN RESULTS\n");
RTPrintf("%.20s-----------------------------------------------------------------------------------------\n", "---------------------------------------------");
{
{
unsigned uComprSpeedOut = (unsigned)(aTests[j].cbCompr / (long double)aTests[j].cNanoCompr * 1000000000.0 / 1024);
unsigned uDecomprSpeedIn = (unsigned)(aTests[j].cbCompr / (long double)aTests[j].cNanoDecompr * 1000000000.0 / 1024);
unsigned uDecomprSpeedOut = (unsigned)(cbTotalKB / (long double)aTests[j].cNanoDecompr * 1000000000.0);
RTPrintf("%-20s %'9u KB/s %'9u KB/s %3u%% %'11llu bytes %'9u KB/s %'9u KB/s",
#if 0
RTPrintf(" [%'14llu / %'14llu ns]\n",
#else
RTPrintf("\n");
#endif
}
else
{
rc = 1;
}
}
if (pszPageFile)
RTPrintf("Input: %'10zu pages from '%s' starting at offset %'lld (%#llx)\n"
" %'11zu bytes\n",
else
RTPrintf("Input: %'10zu pages of generated rubbish %'11zu bytes\n",
/*
* Count zero pages in the data set.
*/
size_t cZeroPages = 0;
{
cZeroPages++;
}
/*
* A little extension to the test, benchmark relevant CRCs.
*/
RTPrintf("\n"
RTPrintf("\n"
RTPrintf("tstCompressionBenchmark: END RESULTS\n");
return rc;
}