Skip to content

Commit

Permalink
Updated test code to output user-friendly values.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanQuatermain committed Apr 21, 2009
1 parent 2e43715 commit cede6b8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
70 changes: 66 additions & 4 deletions Test/ParserComparison/ParserComparison.m
Expand Up @@ -50,6 +50,7 @@
#import "AQXMLParserDelegate.h"

static void usage( void ) __dead2;
static const char * MemorySizeString( mach_vm_size_t size );

static const char * _shortCommandLineArgs = "f:u:ndmah";
static struct option _longCommandLineArgs[] = {
Expand Down Expand Up @@ -100,6 +101,67 @@ static void usage( void )
exit( EX_USAGE );
}

static const char * MemorySizeString( mach_vm_size_t size )
{
enum
{
kSizeIsBytes = 0,
kSizeIsKilobytes,
kSizeIsMegabytes,
kSizeIsGigabytes,
kSizeIsTerabytes,
kSizeIsPetabytes,
kSizeIsExabytes
};

int sizeType = kSizeIsBytes;
double dSize = (double) size;

while ( isgreater(dSize, 1024.0) )
{
dSize = dSize / 1024.0;
sizeType++;
}

NSMutableString * str = [[NSMutableString alloc] initWithFormat: (sizeType == kSizeIsBytes ? @"%.00f" : @"%.02f"), dSize];
switch ( sizeType )
{
default:
case kSizeIsBytes:
[str appendString: @" bytes"];
break;

case kSizeIsKilobytes:
[str appendString: @"KB"];
break;

case kSizeIsMegabytes:
[str appendString: @"MB"];
break;

case kSizeIsGigabytes:
[str appendString: @"GB"];
break;

case kSizeIsTerabytes:
[str appendString: @"TB"];
break;

case kSizeIsPetabytes:
[str appendString: @"PB"];
break;

case kSizeIsExabytes:
[str appendString: @"EB"];
break;
}

NSString * result = [str copy];
[str release];

return ( [[result autorelease] UTF8String] );
}

#pragma mark -

@interface NumberParser : AQXMLParserDelegate
Expand Down Expand Up @@ -160,7 +222,7 @@ static void RunNSDocumentTest( NSURL * url )
mach_vm_size_t end = GetProcessMemoryUsage();
[doc release];

fprintf( stdout, "Peak VM usage: %llu bytes\n", (end - start) );
fprintf( stdout, "Peak VM usage: %s\n", MemorySizeString(end - start) );
}

static void RunNSParserTest( NSURL * url )
Expand All @@ -176,7 +238,7 @@ static void RunNSParserTest( NSURL * url )
(void) [parser parse];

fprintf( stdout, "Parsed %lu numbers\n", (unsigned long)[delegate.set count] );
fprintf( stdout, "Peak VM usage: %llu bytes\n", delegate.maxVMSize );
fprintf( stdout, "Peak VM usage: %s\n", MemorySizeString(delegate.maxVMSize) );

[delegate release];
[parser release];
Expand Down Expand Up @@ -210,7 +272,7 @@ static void RunMappedNSParserTest( NSURL * url )
(void) [parser parse];

fprintf( stdout, "Parsed %lu numbers\n", (unsigned long)[delegate.set count] );
fprintf( stdout, "Peak VM usage: %llu bytes\n", delegate.maxVMSize );
fprintf( stdout, "Peak VM usage: %s\n", MemorySizeString(delegate.maxVMSize) );

[delegate release];
[parser release];
Expand Down Expand Up @@ -245,7 +307,7 @@ static void RunAQParserTest( NSURL * url )
(void) [parser parse];

fprintf( stdout, "Parsed %lu numbers\n", (unsigned long)[delegate.set count] );
fprintf( stdout, "Peak VM usage: %llu bytes\n", delegate.maxVMSize );
fprintf( stdout, "Peak VM usage: %s\n", MemorySizeString(delegate.maxVMSize) );

[parser release];
[delegate release];
Expand Down
Expand Up @@ -221,7 +221,7 @@
1DEB927A08733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Expand Down

0 comments on commit cede6b8

Please sign in to comment.