Skip to content
This repository has been archived by the owner on Mar 15, 2019. It is now read-only.

Commit

Permalink
Updated scaling test results to use CPU cycles instead of picoseconds…
Browse files Browse the repository at this point in the history
…, and with a new "nothing" test to discount loop overheads
  • Loading branch information
Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) committed Jul 29, 2010
1 parent bad9d75 commit 71449f6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
Binary file modified ScalingTestResults.xlsx
Binary file not shown.
33 changes: 25 additions & 8 deletions scalingtest.cpp
Expand Up @@ -12,7 +12,7 @@ Tests how various allocators scale according to block size using a monte-carlo a
#include <math.h>
#include <vector>

#define LOOPS 25000
#define LOOPS 100000
#define MAXBLOCKSIZE (8*1024*1024)

#ifdef WIN32
Expand Down Expand Up @@ -60,7 +60,7 @@ static void *mmap_wrapper(size_t size)
#ifdef WIN32
return VirtualAlloc(NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
#else
return mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
return mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
#endif
}
static void munmap_wrapper(void *mem, size_t size)
Expand All @@ -73,10 +73,12 @@ static void munmap_wrapper(void *mem, size_t size)
}
static void *userpagemalloc_wrapper(size_t size)
{
assert(!(size & (PAGE_SIZE-1)));
return userpage_malloc(size, 0);
}
static void userpagefree_wrapper(void *mem, size_t size)
{
assert(!(size & (PAGE_SIZE-1)));
userpage_free(mem, size);
}
static mspace mymspace = create_mspace(0,0);
Expand All @@ -88,6 +90,13 @@ static void dlfree(void *mem, size_t size)
{
mspace_free(mymspace, mem);
}
static void *nothing_malloc(size_t size)
{
return 0;
}
static void nothing_free(void *mem, size_t size)
{
}

struct Allocator
{
Expand All @@ -105,7 +114,8 @@ static Allocator allocators[]={
#else
{ "System VirtualAlloc()", "sysmmap", PAGE_SIZE, 0, &mmap_wrapper, &munmap_wrapper },
#endif
{ "User mode page allocator", "usermodemmap", PAGE_SIZE, 0, &userpagemalloc_wrapper, &userpagefree_wrapper }
{ "User mode page allocator", "usermodemmap", PAGE_SIZE, 0, &userpagemalloc_wrapper, &userpagefree_wrapper },
{ "Nothing", "nothing", 0, 0, &nothing_malloc, &nothing_free }
};

int main(void)
Expand All @@ -121,6 +131,11 @@ int main(void)
Allocator &allocator=allocators[allocatoridx];
allocator.minsizeshift=allocator.minsize ? nedtriebitscanr(allocator.minsize) : (allocator.minsize=1<<3, 3);
printf("\nYou chose allocator %d (%s) with minsizeshift=%u\n", allocatoridx+1, allocator.name, allocator.minsizeshift);
//if(allocator.malloc==&userpagemalloc_wrapper)
{
//printf("Preallocating user mode page allocator memory ... \n");
//userpage_free(userpage_malloc(3ULL*1024*1024*1024, 0), 3ULL*1024*1024*1024);
}
for(usCount s=GetUsCount(); GetUsCount()-s<3000000000000ULL;);
printf("Testing ...\n");

Expand All @@ -147,16 +162,18 @@ int main(void)
start=GetUsCount();
allocator.free(ptrp->mem, ptrp->size);
end=GetUsCount();
//pair<usCount, size_t> &v=bins[nedtriebitscanr(ptrp->size)];
//v.first+=end-start;
//v.second++;
pair<usCount, size_t> &v=bins[nedtriebitscanr(ptrp->size)];
v.first+=end-start;
ptrp->mem=0; ptrp->size=0;
}
start=GetUsCount();
ptrp->mem=allocator.malloc(blksize);
ptrp->size=blksize;
for(volatile char *p=(volatile char *)ptrp->mem, *pend=(volatile char *)ptrp->mem+blksize; p<pend; p+=PAGE_SIZE)
*p;
//if(allocator.malloc!=&userpagemalloc_wrapper)
{
//for(volatile char *p=(volatile char *)ptrp->mem, *pend=(volatile char *)ptrp->mem+blksize; p<pend; p+=PAGE_SIZE)
// *p;
}
end=GetUsCount();
if(++ptrp==ptrs+512) ptrp=ptrs;
pair<usCount, size_t> &v=bins[blksize ? nedtriebitscanr(blksize) : 0];
Expand Down
56 changes: 29 additions & 27 deletions scalingtest.vcproj
Expand Up @@ -91,12 +91,11 @@
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
Expand All @@ -112,16 +111,15 @@
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="2"
FloatingPointModel="2"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
Expand All @@ -137,13 +135,11 @@
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
UACExecutionLevel="0"
LinkIncremental="2"
UACExecutionLevel="2"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
Expand All @@ -168,11 +164,12 @@
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
Expand All @@ -188,15 +185,16 @@
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="2"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
Expand All @@ -212,10 +210,14 @@
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
LinkIncremental="1"
UACExecutionLevel="0"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="17"
LargeAddressAware="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
Expand Down

0 comments on commit 71449f6

Please sign in to comment.