ICU-6441 add perf test for this ticket, testing ucnv_countAvailable() speed and memory consumption

X-SVN-Rev: 25742
This commit is contained in:
Markus Scherer 2009-04-07 18:41:01 +00:00
parent 8ee4058f62
commit 2a5c55f947
3 changed files with 319 additions and 1 deletions

View File

@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "charperf", "charperf\charperf.vcproj", "{D850A4B6-7D94-476E-9392-E9272DA4EAAF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "normperf", "normperf\normperf.vcproj", "{56CCC661-8D33-4F0A-B62F-C619CE843C68}"
@ -22,6 +22,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "strsrchperf", "strsrchperf\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "utrie2perf", "utrie2perf\utrie2perf.vcproj", "{B9458CB3-9B09-402A-8C4C-43B6D0EA9691}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ucnvavailperf", "ucnvavailperf\ucnvavailperf.vcproj", "{EE2259BF-280D-4E0E-8A08-D77A26AE4191}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -116,6 +118,12 @@ Global
{B9458CB3-9B09-402A-8C4C-43B6D0EA9691}.Release|Win32.ActiveCfg = Release|Win32
{B9458CB3-9B09-402A-8C4C-43B6D0EA9691}.Release|Win32.Build.0 = Release|Win32
{B9458CB3-9B09-402A-8C4C-43B6D0EA9691}.Release|x64.ActiveCfg = Release|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Debug|Win32.ActiveCfg = Debug|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Debug|Win32.Build.0 = Debug|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Debug|x64.ActiveCfg = Debug|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Release|Win32.ActiveCfg = Release|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Release|Win32.Build.0 = Release|Win32
{EE2259BF-280D-4E0E-8A08-D77A26AE4191}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,129 @@
/*
*******************************************************************************
*
* Copyright (C) 2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: ucnvavailperf.cpp
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2009apr06
* created by: Markus W. Scherer
*
* Test performance (time & memory) of ucnv_countAvailable(),
* for a before-and-after comparison of
* ticket 6441: make ucnv_countAvailable() not fully load converters
*
* Run with one optional command-line argument:
* You can specify the path to the ICU data directory.
*
* I built the common (icuuc) library with the following modification,
* switching between old (pre-ticket-6441) behavior of actually
* trying to load all converters and new behavior of just doing enough
* to test availability.
*
* Code in the ucnv_bld.c haveAvailableConverterList() function:
#if 0
// old pre-ticket-6441 behavior
ucnv_close(ucnv_createConverter(&tempConverter, converterName, &localStatus));
if (U_SUCCESS(localStatus)) {
#else
// new behavior
if (ucnv_canCreateConverter(converterName, &localStatus)) {
#endif
*/
#include <malloc.h>
#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/putil.h"
#include "unicode/uclean.h"
#include "unicode/ucnv.h"
#include "unicode/utimer.h"
static size_t icuMemUsage = 0;
U_CDECL_BEGIN
void *U_CALLCONV
my_alloc(const void *context, size_t size) {
size_t *p = (size_t *)malloc(size + sizeof(size_t));
if (p != NULL) {
icuMemUsage += size;
*p = size;
return p + 1;
} else {
return NULL;
}
}
void U_CALLCONV
my_free(const void *context, void *mem) {
if (mem != NULL) {
const size_t *p = (const size_t *)mem - 1;
icuMemUsage -= *p;
free((void *)p);
}
}
// Not used in the common library.
void *U_CALLCONV
my_realloc(const void *context, void *mem, size_t size) {
my_free(context, mem);
return NULL;
}
U_CDECL_END
int main(int argc, const char *argv[]) {
UErrorCode errorCode = U_ZERO_ERROR;
// Hook in our own memory allocation functions so that we can measure
// the memory usage.
u_setMemoryFunctions(NULL, my_alloc, my_realloc, my_free, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr,
"u_setMemoryFunctions() failed - %s\n",
u_errorName(errorCode));
return errorCode;
}
if (argc > 1) {
printf("u_setDataDirectory(%s)\n", argv[1]);
u_setDataDirectory(argv[1]);
}
// Preload a purely algorithmic converter via an alias,
// to make sure that relevant data can be loaded and to set up
// caches and such that are needed even if none of the data-driven
// converters needs to be loaded.
ucnv_close(ucnv_open("ibm-1208", &errorCode));
if(U_FAILURE(errorCode)) {
fprintf(stderr,
"unable to open UTF-8 converter via an alias - %s\n",
u_errorName(errorCode));
return errorCode;
}
printf("memory usage after ucnv_open(ibm-1208): %lu\n", (long)icuMemUsage);
UTimer start_time;
utimer_getTime(&start_time);
// Measure the time to find out the list of actually available converters.
int32_t count = ucnv_countAvailable();
double elapsed = utimer_getElapsedSeconds(&start_time);
printf("ucnv_countAvailable() reports that %d converters are available.\n", count);
printf("ucnv_countAvailable() took %g seconds to figure this out.\n", elapsed);
printf("memory usage after ucnv_countAvailable(): %lu\n", (long)icuMemUsage);
ucnv_flushCache();
printf("memory usage after ucnv_flushCache(): %lu\n", (long)icuMemUsage);
u_cleanup();
printf("memory usage after u_cleanup(): %lu\n", (long)icuMemUsage);
return 0;
}

View File

@ -0,0 +1,181 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="ucnvavailperf"
ProjectGUID="{EE2259BF-280D-4E0E-8A08-D77A26AE4191}"
RootNamespace="ucnvavailperf"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\x86\$(ConfigurationName)"
IntermediateDirectory=".\x86\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\tools\ctestfw;..\..\..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icutestd.lib winmm.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\..\lib\"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\x86\$(ConfigurationName)"
IntermediateDirectory=".\x86\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\..\..\tools\ctestfw;..\..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icutest.lib winmm.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\..\lib\"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\ucnvavailperf.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>