* Source/GSPrivate.h (GS_REPLACE_CONSTANT_STRING): New macro.

* Source/externs.m: Initialize constant strings statically.
	(GSBuildStrings): Replace static strings with dynamic
	versions.
	* Testing/benchmark.m: Added tests for NSString -hash and
	-copy.  Aligned ouput.
	* Testing/externs.m: New test.
	* Testing/GNUmakefile: Added externs.m test.  Activated
	ADDITIONAL_TOOLS tests excluding gstcpport tests.

	* Source/Additions/GSCategories.m: Adjust declared lock type.
	Added comment.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18058 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Ayers 2003-11-06 21:11:39 +00:00
parent 4d1f1825c1
commit fe44315405
7 changed files with 439 additions and 227 deletions

View file

@ -1,3 +1,18 @@
2003-11-06 David Ayers <d.ayers@inode.at>
* Source/GSPrivate.h (GS_REPLACE_CONSTANT_STRING): New macro.
* Source/externs.m: Initialize constant strings statically.
(GSBuildStrings): Replace static strings with dynamic
versions.
* Testing/benchmark.m: Added tests for NSString -hash and
-copy. Aligned ouput.
* Testing/externs.m: New test.
* Testing/GNUmakefile: Added externs.m test. Activated
ADDITIONAL_TOOLS tests excluding gstcpport tests.
* Source/Additions/GSCategories.m: Adjust declared lock type.
Added comment.
2003-11-05 18:26 Richard Frith-Macdonald <rfm@gnu.org>
* SSL/GSSSLHandle.m: Add support for server end handles.

View file

@ -880,7 +880,7 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
* GNUstep specific (non-standard) additions to the NSLock class.
*/
static NSRecursiveLock *local_lock = nil;
static GSLazyRecursiveLock *local_lock = nil;
/*
This class only exists to provide
@ -897,9 +897,13 @@ static NSRecursiveLock *local_lock = nil;
{
if (local_lock == nil)
{
/* As we do not know whether creating custom locks
may implicitly create other locks,
we use a recursive lock. */
local_lock = [GSLazyRecursiveLock new];
}
}
@end
GS_STATIC_INLINE id

View file

@ -48,6 +48,28 @@
NSZoneFree(NSDefaultMallocZone(), _base); \
}
/**
* Macro to consistently replace public accessable
* constant strings with dynamically allocated versions.
* This method assumes an initialzed NSStringClass symbol
* which contains the Class object of NSString. <br>
* Most public accesable strings are used in collection classes
* like NSDictionary, and therefor tend to receive -isEqual:
* messages (and therefore -hash) rather often. Statically
* allocated strings must calculate thier hash values where
* dynamically allocated strings can store them. This optimization
* is by far more effective than using NSString * const.
* The backdraw is that the memory managent cannot enforce these values
* to remain unaltered as it would for variables declared NSString * const.
* Yet the optimization of the stored hash value is currently deemed
* more important.
*/
#define GS_REPLACE_CONSTANT_STRING(ID) \
ID = [[NSStringClass alloc] initWithCString: [ID cString]]
/* Using cString here is OK here
because NXConstantString returns a pointer
to it's internal pointer. */
/*
* Function to get the name of a string encoding as an NSString.
*/

View file

@ -28,6 +28,8 @@
#include "Foundation/NSArray.h"
#include "Foundation/NSException.h"
#include "GSPrivate.h"
/* Global lock to be used by classes when operating on any global
data that invoke other methods which also access global; thus,
creating the potential for deadlock. */
@ -35,39 +37,39 @@
NSRecursiveLock *gnustep_global_lock = nil;
/*
* Connection Notification Strings.
* NSConnection Notification Strings.
*/
NSString *NSConnectionDidDieNotification;
NSString *NSConnectionDidDieNotification = @"NSConnectionDidDieNotification";
NSString *NSConnectionDidInitializeNotification;
NSString *NSConnectionDidInitializeNotification = @"NSConnectionDidInitializeNotification";
/*
* NSThread Notifications
*/
NSString *NSWillBecomeMultiThreadedNotification;
NSString *NSWillBecomeMultiThreadedNotification = @"NSWillBecomeMultiThreadedNotification";
NSString *NSThreadDidStartNotification;
NSString *NSThreadDidStartNotification = @"NSThreadDidStartNotification";
NSString *NSThreadWillExitNotification;
NSString *NSThreadWillExitNotification = @"NSThreadWillExitNotification";
/*
* Port Notifications
*/
NSString *PortBecameInvalidNotification;
NSString *PortBecameInvalidNotification = @"PortBecameInvalidNotification";
NSString *InPortClientBecameInvalidNotification;
NSString *InPortClientBecameInvalidNotification = @"InPortClientBecameInvalidNotification";
NSString *InPortAcceptedClientNotification;
NSString *InPortAcceptedClientNotification = @"InPortAcceptedClientNotification";
NSString *NSPortDidBecomeInvalidNotification;
NSString *NSPortDidBecomeInvalidNotification = @"NSPortDidBecomeInvalidNotification";
/* RunLoop modes */
NSString *NSConnectionReplyMode;
NSString *NSConnectionReplyMode = @"NSConnectionReplyMode";
@ -75,133 +77,137 @@ NSString *NSConnectionReplyMode;
NSUncaughtExceptionHandler *_NSUncaughtExceptionHandler;
/* NSBundle */
NSString *NSBundleDidLoadNotification;
NSString *NSBundleDidLoadNotification = @"NSBundleDidLoadNotification";
NSString *NSShowNonLocalizedStrings;
NSString *NSShowNonLocalizedStrings = @"NSShowNonLocalizedStrings";
NSString *NSLoadedClasses;
NSString *NSLoadedClasses = @"NSLoadedClasses";
/* Stream */
NSString *StreamException;
NSString *StreamException = @"StreamException";
/* Standard domains */
NSString *NSArgumentDomain;
NSString *NSArgumentDomain = @"NSArgumentDomain";
NSString *NSGlobalDomain;
NSString *NSGlobalDomain = @"NSGlobalDomain";
NSString *NSRegistrationDomain;
NSString *NSRegistrationDomain = @"NSRegistrationDomain";
/* Public notification */
NSString *NSUserDefaultsDidChangeNotification;
NSString *NSUserDefaultsDidChangeNotification = @"NSUserDefaultsDidChangeNotification";
/* Keys for language-dependent information */
NSString *NSWeekDayNameArray;
NSString *NSWeekDayNameArray = @"NSWeekDayNameArray";
NSString *NSShortWeekDayNameArray;
NSString *NSShortWeekDayNameArray = @"NSShortWeekDayNameArray";
NSString *NSMonthNameArray;
NSString *NSMonthNameArray = @"NSMonthNameArray";
NSString *NSShortMonthNameArray;
NSString *NSShortMonthNameArray = @"NSShortMonthNameArray";
NSString *NSTimeFormatString;
NSString *NSTimeFormatString = @"NSTimeFormatString";
NSString *NSDateFormatString;
NSString *NSDateFormatString = @"NSDateFormatString";
NSString *NSShortDateFormatString;
NSString *NSShortDateFormatString = @"NSShortDateFormatString";
NSString *NSTimeDateFormatString;
NSString *NSTimeDateFormatString = @"NSTimeDateFormatString";
NSString *NSShortTimeDateFormatString;
NSString *NSShortTimeDateFormatString = @"NSShortTimeDateFormatString";
NSString *NSCurrencySymbol;
NSString *NSCurrencySymbol = @"NSCurrencySymbol";
NSString *NSDecimalSeparator;
NSString *NSDecimalSeparator = @"NSDecimalSeparator";
NSString *NSThousandsSeparator;
NSString *NSThousandsSeparator = @"NSThousandsSeparator";
NSString *NSInternationalCurrencyString;
NSString *NSInternationalCurrencyString = @"NSInternationalCurrencyString";
NSString *NSCurrencyString;
NSString *NSCurrencyString = @"NSCurrencyString";
NSString *NSNegativeCurrencyFormatString;
NSString *NSNegativeCurrencyFormatString = @"NSNegativeCurrencyFormatString";
NSString *NSPositiveCurrencyFormatString;
NSString *NSPositiveCurrencyFormatString = @"NSPositiveCurrencyFormatString";
NSString *NSDecimalDigits;
NSString *NSDecimalDigits = @"NSDecimalDigits";
NSString *NSAMPMDesignation;
NSString *NSAMPMDesignation = @"NSAMPMDesignation";
NSString *NSHourNameDesignations;
NSString *NSHourNameDesignations = @"NSHourNameDesignations";
NSString *NSYearMonthWeekDesignations;
NSString *NSYearMonthWeekDesignations = @"NSYearMonthWeekDesignations";
NSString *NSEarlierTimeDesignations;
NSString *NSEarlierTimeDesignations = @"NSEarlierTimeDesignations";
NSString *NSLaterTimeDesignations;
NSString *NSLaterTimeDesignations = @"NSLaterTimeDesignations";
NSString *NSThisDayDesignations;
NSString *NSThisDayDesignations = @"NSThisDayDesignations";
NSString *NSNextDayDesignations;
NSString *NSNextDayDesignations = @"NSNextDayDesignations";
NSString *NSNextNextDayDesignations;
NSString *NSNextNextDayDesignations = @"NSNextNextDayDesignations";
NSString *NSPriorDayDesignations;
NSString *NSPriorDayDesignations = @"NSPriorDayDesignations";
NSString *NSDateTimeOrdering;
NSString *NSDateTimeOrdering = @"NSDateTimeOrdering";
/* These are in OPENSTEP 4.2 */
NSString *NSLanguageCode;
NSString *NSLanguageCode = @"NSLanguageCode";
NSString *NSLanguageName;
NSString *NSLanguageName = @"NSLanguageName";
NSString *NSFormalName;
NSString *NSFormalName = @"NSFormalName";
/* For GNUstep */
NSString *NSLocale;
NSString *NSLocale = @"NSLocale";
/*
* Keys for the NSDictionary returned by [NSConnection -statistics]
*/
/* These in OPENSTEP 4.2 */
NSString *NSConnectionRepliesReceived;
NSString *NSConnectionRepliesReceived = @"NSConnectionRepliesReceived";
NSString *NSConnectionRepliesSent;
NSString *NSConnectionRepliesSent = @"NSConnectionRepliesSent";
NSString *NSConnectionRequestsReceived;
NSString *NSConnectionRequestsReceived = @"NSConnectionRequestsReceived";
NSString *NSConnectionRequestsSent;
NSString *NSConnectionRequestsSent = @"NSConnectionRequestsSent";
/* These Are GNUstep extras */
NSString *NSConnectionLocalCount;
NSString *NSConnectionLocalCount = @"NSConnectionLocalCount";
NSString *NSConnectionProxyCount;
NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
/* Class description notification */
NSString *NSClassDescriptionNeededForClassNotification;
NSString *NSClassDescriptionNeededForClassNotification = @"NSClassDescriptionNeededForClassNotification";
/*
* Setup function called when NSString is initialised.
* We make all the constant strings not be constant strings so they can
* cache their hash values and be used much more efficiently as keys in
* dictionaries etc.
* Opimization function called when NSObject is initialised.
* We replace all the constant strings so they can
* cache their hash values and be used much more efficiently as keys in
* dictionaries etc.
* We initialize with constant strings so that
* code executed before NSObject +initialize calls us,
* will have valid values.
*/
void
GSBuildStrings()
{
static Class SClass = 0;
static Class NSStringClass = 0;
if (SClass == 0)
if (NSStringClass == 0)
{
SClass = [NSString class];
NSStringClass = [NSString class];
/*
* Ensure that NSString is initialized ... because we are called
@ -210,131 +216,64 @@ GSBuildStrings()
* Use performSelector: to avoid compiler warning about clash of
* return value types in two different versions of initialize.
*/
[SClass performSelector: @selector(initialize)];
[NSStringClass performSelector: @selector(initialize)];
InPortAcceptedClientNotification
= [[SClass alloc] initWithCString:
"InPortAcceptedClientNotification"];
InPortClientBecameInvalidNotification
= [[SClass alloc] initWithCString:
"InPortClientBecameInvalidNotification"];
NSAMPMDesignation
= [[SClass alloc] initWithCString: "NSAMPMDesignation"];
NSArgumentDomain
= [[SClass alloc] initWithCString: "NSArgumentDomain"];
NSBundleDidLoadNotification
= [[SClass alloc] initWithCString: "NSBundleDidLoadNotification"];
NSConnectionDidDieNotification
= [[SClass alloc] initWithCString:
"NSConnectionDidDieNotification"];
NSConnectionDidInitializeNotification
= [[SClass alloc] initWithCString:
"NSConnectionDidInitializeNotification"];
NSConnectionLocalCount
= [[SClass alloc] initWithCString: "NSConnectionLocalCount"];
NSConnectionProxyCount
= [[SClass alloc] initWithCString: "NSConnectionProxyCount"];
NSConnectionRepliesReceived
= [[SClass alloc] initWithCString: "NSConnectionRepliesReceived"];
NSConnectionRepliesSent
= [[SClass alloc] initWithCString: "NSConnectionRepliesSent"];
NSConnectionReplyMode
= [[SClass alloc] initWithCString: "NSConnectionReplyMode"];
NSConnectionRequestsReceived
= [[SClass alloc] initWithCString: "NSConnectionRequestsReceived"];
NSConnectionRequestsSent
= [[SClass alloc] initWithCString: "NSConnectionRequestsSent"];
NSCurrencyString
= [[SClass alloc] initWithCString: "NSCurrencyString"];
NSCurrencySymbol
= [[SClass alloc] initWithCString: "NSCurrencySymbol"];
NSDateFormatString
= [[SClass alloc] initWithCString: "NSDateFormatString"];
NSDateTimeOrdering
= [[SClass alloc] initWithCString: "NSDateTimeOrdering"];
NSDecimalDigits
= [[SClass alloc] initWithCString: "NSDecimalDigits"];
NSDecimalSeparator
= [[SClass alloc] initWithCString: "NSDecimalSeparator"];
NSEarlierTimeDesignations
= [[SClass alloc] initWithCString: "NSEarlierTimeDesignations"];
NSFormalName
= [[SClass alloc] initWithCString: "NSFormalName"];
NSGlobalDomain
= [[SClass alloc] initWithCString: "NSGlobalDomain"];
NSHourNameDesignations
= [[SClass alloc] initWithCString: "NSHourNameDesignations"];
NSInternationalCurrencyString
= [[SClass alloc] initWithCString: "NSInternationalCurrencyString"];
NSLanguageCode
= [[SClass alloc] initWithCString: "NSLanguageCode"];
NSLanguageName
= [[SClass alloc] initWithCString: "NSLanguageName"];
NSLaterTimeDesignations
= [[SClass alloc] initWithCString: "NSLaterTimeDesignations"];
NSLoadedClasses
= [[SClass alloc] initWithCString: "NSLoadedClasses"];
NSLocale
= [[SClass alloc] initWithCString: "NSLocale"];
NSMonthNameArray
= [[SClass alloc] initWithCString: "NSMonthNameArray"];
NSNegativeCurrencyFormatString
= [[SClass alloc] initWithCString:
"NSNegativeCurrencyFormatString"];
NSNextDayDesignations
= [[SClass alloc] initWithCString: "NSNextDayDesignations"];
NSNextNextDayDesignations
= [[SClass alloc] initWithCString: "NSNextNextDayDesignations"];
NSPortDidBecomeInvalidNotification
= [[SClass alloc] initWithCString:
"NSPortDidBecomeInvalidNotification"];
NSPositiveCurrencyFormatString
= [[SClass alloc] initWithCString:
"NSPositiveCurrencyFormatString"];
NSPriorDayDesignations
= [[SClass alloc] initWithCString: "NSPriorDayDesignations"];
NSRegistrationDomain
= [[SClass alloc] initWithCString: "NSRegistrationDomain"];
NSShortDateFormatString
= [[SClass alloc] initWithCString: "NSShortDateFormatString"];
NSShortMonthNameArray
= [[SClass alloc] initWithCString: "NSShortMonthNameArray"];
NSShortTimeDateFormatString
= [[SClass alloc] initWithCString: "NSShortTimeDateFormatString"];
NSShortWeekDayNameArray
= [[SClass alloc] initWithCString: "NSShortWeekDayNameArray"];
NSShowNonLocalizedStrings
= [[SClass alloc] initWithCString: "NSShowNonLocalizedStrings"];
NSThisDayDesignations
= [[SClass alloc] initWithCString: "NSThisDayDesignations"];
NSThousandsSeparator
= [[SClass alloc] initWithCString: "NSThousandsSeparator"];
NSThreadDidStartNotification
= [[SClass alloc] initWithCString: "NSThreadDidStartNotification"];
NSThreadWillExitNotification
= [[SClass alloc] initWithCString: "NSThreadWillExitNotification"];
NSTimeDateFormatString
= [[SClass alloc] initWithCString: "NSTimeDateFormatString"];
NSTimeFormatString
= [[SClass alloc] initWithCString: "NSTimeFormatString"];
NSUserDefaultsDidChangeNotification
= [[SClass alloc] initWithCString:
"NSUserDefaultsDidChangeNotification"];
NSWeekDayNameArray
= [[SClass alloc] initWithCString: "NSWeekDayNameArray"];
NSWillBecomeMultiThreadedNotification
= [[SClass alloc] initWithCString:
"NSWillBecomeMultiThreadedNotification"];
NSYearMonthWeekDesignations
= [[SClass alloc] initWithCString: "NSYearMonthWeekDesignations"];
PortBecameInvalidNotification
= [[SClass alloc] initWithCString: "PortBecameInvalidNotification"];
StreamException
= [[SClass alloc] initWithCString: "StreamException"];
NSClassDescriptionNeededForClassNotification
= [[SClass alloc] initWithCString:
"NSClassDescriptionNeededForClassNotification"];
GS_REPLACE_CONSTANT_STRING(InPortAcceptedClientNotification);
GS_REPLACE_CONSTANT_STRING(InPortClientBecameInvalidNotification);
GS_REPLACE_CONSTANT_STRING(NSAMPMDesignation);
GS_REPLACE_CONSTANT_STRING(NSArgumentDomain);
GS_REPLACE_CONSTANT_STRING(NSBundleDidLoadNotification);
GS_REPLACE_CONSTANT_STRING(NSClassDescriptionNeededForClassNotification);
GS_REPLACE_CONSTANT_STRING(NSConnectionDidDieNotification);
GS_REPLACE_CONSTANT_STRING(NSConnectionDidInitializeNotification);
GS_REPLACE_CONSTANT_STRING(NSConnectionLocalCount);
GS_REPLACE_CONSTANT_STRING(NSConnectionProxyCount);
GS_REPLACE_CONSTANT_STRING(NSConnectionRepliesReceived);
GS_REPLACE_CONSTANT_STRING(NSConnectionRepliesSent);
GS_REPLACE_CONSTANT_STRING(NSConnectionReplyMode);
GS_REPLACE_CONSTANT_STRING(NSConnectionRequestsReceived);
GS_REPLACE_CONSTANT_STRING(NSConnectionRequestsSent);
GS_REPLACE_CONSTANT_STRING(NSCurrencyString);
GS_REPLACE_CONSTANT_STRING(NSCurrencySymbol);
GS_REPLACE_CONSTANT_STRING(NSDateFormatString);
GS_REPLACE_CONSTANT_STRING(NSDateTimeOrdering);
GS_REPLACE_CONSTANT_STRING(NSDecimalDigits);
GS_REPLACE_CONSTANT_STRING(NSDecimalSeparator);
GS_REPLACE_CONSTANT_STRING(NSEarlierTimeDesignations);
GS_REPLACE_CONSTANT_STRING(NSFormalName);
GS_REPLACE_CONSTANT_STRING(NSGlobalDomain);
GS_REPLACE_CONSTANT_STRING(NSHourNameDesignations);
GS_REPLACE_CONSTANT_STRING(NSInternationalCurrencyString);
GS_REPLACE_CONSTANT_STRING(NSLanguageCode);
GS_REPLACE_CONSTANT_STRING(NSLanguageName);
GS_REPLACE_CONSTANT_STRING(NSLaterTimeDesignations);
GS_REPLACE_CONSTANT_STRING(NSLoadedClasses);
GS_REPLACE_CONSTANT_STRING(NSLocale);
GS_REPLACE_CONSTANT_STRING(NSMonthNameArray);
GS_REPLACE_CONSTANT_STRING(NSNegativeCurrencyFormatString);
GS_REPLACE_CONSTANT_STRING(NSNextDayDesignations);
GS_REPLACE_CONSTANT_STRING(NSNextNextDayDesignations);
GS_REPLACE_CONSTANT_STRING(NSPortDidBecomeInvalidNotification);
GS_REPLACE_CONSTANT_STRING(NSPositiveCurrencyFormatString);
GS_REPLACE_CONSTANT_STRING(NSPriorDayDesignations);
GS_REPLACE_CONSTANT_STRING(NSRegistrationDomain);
GS_REPLACE_CONSTANT_STRING(NSShortDateFormatString);
GS_REPLACE_CONSTANT_STRING(NSShortMonthNameArray);
GS_REPLACE_CONSTANT_STRING(NSShortTimeDateFormatString);
GS_REPLACE_CONSTANT_STRING(NSShortWeekDayNameArray);
GS_REPLACE_CONSTANT_STRING(NSShowNonLocalizedStrings);
GS_REPLACE_CONSTANT_STRING(NSThisDayDesignations);
GS_REPLACE_CONSTANT_STRING(NSThousandsSeparator);
GS_REPLACE_CONSTANT_STRING(NSThreadDidStartNotification);
GS_REPLACE_CONSTANT_STRING(NSThreadWillExitNotification);
GS_REPLACE_CONSTANT_STRING(NSTimeDateFormatString);
GS_REPLACE_CONSTANT_STRING(NSTimeFormatString);
GS_REPLACE_CONSTANT_STRING(NSUserDefaultsDidChangeNotification);
GS_REPLACE_CONSTANT_STRING(NSWeekDayNameArray);
GS_REPLACE_CONSTANT_STRING(NSWillBecomeMultiThreadedNotification);
GS_REPLACE_CONSTANT_STRING(NSYearMonthWeekDesignations);
GS_REPLACE_CONSTANT_STRING(PortBecameInvalidNotification);
GS_REPLACE_CONSTANT_STRING(StreamException);
}
}

View file

@ -35,6 +35,7 @@ CHECKABLE_TOOLS = \
benchmark \
call \
containers \
exported-strings \
fref \
gslock \
nsarchiver \
@ -70,13 +71,11 @@ TEST_TOOL_NAME = $(CHECKABLE_TOOLS)
# Don't make these normally
ADDITIONAL_TOOLS = \
diningPhilosophers \
gstcpport-client \
gstcpport-server \
nsconnection_client \
nsconnection_server \
# TEST_TOOL_NAME += nsconnection_client nsconnection_server
TEST_TOOL_NAME += nsconnection_client nsconnection_server $(ADDITIONAL_TOOLS)
TEST_TOOL_NAME += $(ADDITIONAL_TOOLS)
# TEST_TOOL_NAME += gstcpport-client gstcpport-server
# The tool Objective-C source files to be compiled
awake_OBJC_FILES = awake.m
@ -85,6 +84,7 @@ benchmark_OBJC_FILES = benchmark.m
call_OBJC_FILES = call.m
containers_OBJC_FILES = containers.m
diningPhilosophers_OBJC_FILES = diningPhilosophers.m
exported-strings_OBJC_FILES = exported-strings.m
fref_OBJC_FILES = fref.m
gslock_OBJC_FILES = gslock.m
gstcpport-client_OBJC_FILES = gstcpport-client.m

View file

@ -80,7 +80,7 @@ bench_object()
}
END_TIMER;
baseline = [eTime timeIntervalSinceDate: sTime];
PRINT_TIMER("Baseline: 10 method calls");
PRINT_TIMER("Baseline: 10 method calls\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT; i++)
@ -99,7 +99,7 @@ bench_object()
i = [NSMutableDictionary class];
}
END_TIMER;
PRINT_TIMER("Class: 10 class method calls");
PRINT_TIMER("Class: 10 class method calls\t\t");
obj = [MyObject new];
@ -110,7 +110,7 @@ bench_object()
i = [obj self];
}
END_TIMER;
PRINT_TIMER_NO_BASELINE("Category: 10 super calls");
PRINT_TIMER_NO_BASELINE("Category: 10 super calls\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT; i++)
@ -129,7 +129,7 @@ bench_object()
i = NSClassFromString (@"NSMutableDictionary");
}
END_TIMER;
PRINT_TIMER("Function: 10 NSClassFromStr");
PRINT_TIMER("Function: 10 NSClassFromStr\t\t");
START_TIMER;
myZone = NSCreateZone(2048, 2048, 1);
@ -140,7 +140,7 @@ bench_object()
}
NSRecycleZone(myZone);
END_TIMER;
PRINT_TIMER("Function: 1 zone alloc/free");
PRINT_TIMER("Function: 1 zone alloc/free\t\t");
START_TIMER;
myZone = NSCreateZone(2048, 2048, 0);
@ -151,7 +151,7 @@ bench_object()
}
NSRecycleZone(myZone);
END_TIMER;
PRINT_TIMER("Function: 1 zone2alloc/free");
PRINT_TIMER("Function: 1 zone2alloc/free\t\t");
myZone = NSDefaultMallocZone();
START_TIMER;
@ -161,7 +161,7 @@ bench_object()
NSZoneFree(myZone, mem);
}
END_TIMER;
PRINT_TIMER("Function: 1 def alloc/free");
PRINT_TIMER("Function: 1 def alloc/free\t\t");
START_TIMER;
myZone = NSCreateZone(2048, 2048, 1);
@ -172,7 +172,7 @@ bench_object()
}
NSRecycleZone(myZone);
END_TIMER;
PRINT_TIMER("NSObject: 1 zone all/init/rel");
PRINT_TIMER("NSObject: 1 zone all/init/rel\t\t");
START_TIMER;
myZone = NSCreateZone(2048, 2048, 0);
@ -183,7 +183,7 @@ bench_object()
}
NSRecycleZone(myZone);
END_TIMER;
PRINT_TIMER("NSObject: 1 zone2all/init/rel");
PRINT_TIMER("NSObject: 1 zone2all/init/rel\t\t");
myZone = NSDefaultMallocZone();
START_TIMER;
@ -193,7 +193,7 @@ bench_object()
[obj release];
}
END_TIMER;
PRINT_TIMER("NSObject: 1 def all/init/rel");
PRINT_TIMER("NSObject: 1 def all/init/rel\t\t");
obj = [rootClass new];
START_TIMER;
@ -203,7 +203,7 @@ bench_object()
[obj release];
}
END_TIMER;
PRINT_TIMER("NSObject: 10 retain/rel");
PRINT_TIMER("NSObject: 10 retain/rel\t\t");
[obj release];
obj = [rootClass new];
@ -214,7 +214,7 @@ bench_object()
[obj retain];
}
END_TIMER;
PRINT_TIMER("NSObject: 10 autorel/ret");
PRINT_TIMER("NSObject: 10 autorel/ret\t\t");
[obj release];
START_TIMER;
@ -223,7 +223,7 @@ bench_object()
[rootClass instancesRespondToSelector: @selector(hash)];
}
END_TIMER;
PRINT_TIMER("ObjC: 10 inst responds to sel");
PRINT_TIMER("ObjC: 10 inst responds to sel\t\t");
mutex = objc_mutex_allocate();
START_TIMER;
@ -233,7 +233,7 @@ bench_object()
objc_mutex_unlock(mutex);
}
END_TIMER;
PRINT_TIMER("ObjC: 10 objc_mutex_lock/unl");
PRINT_TIMER("ObjC: 10 objc_mutex_lock/unl\t\t");
objc_mutex_deallocate(mutex);
obj = [NSLock new];
@ -244,7 +244,7 @@ bench_object()
[obj unlock];
}
END_TIMER;
PRINT_TIMER("NSLock: 10 lock/unlock");
PRINT_TIMER("NSLock: 10 lock/unlock\t\t");
[obj release];
@ -273,7 +273,7 @@ bench_array()
[array addObject: strings[i/10]];
}
END_TIMER;
PRINT_TIMER("NSArray (10 addObject:)");
PRINT_TIMER("NSArray (10 addObject:)\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT/100; i++)
@ -281,7 +281,7 @@ bench_array()
[array indexOfObject: strings[i]];
}
END_TIMER;
PRINT_TIMER("NSArray (1/100 indexOfObj)");
PRINT_TIMER("NSArray (1/100 indexOfObj)\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT/100; i++)
@ -289,7 +289,7 @@ bench_array()
[array indexOfObjectIdenticalTo: strings[i]];
}
END_TIMER;
PRINT_TIMER("NSArray (1/100 indexIdent)");
PRINT_TIMER("NSArray (1/100 indexIdent)\t\t");
START_TIMER;
for (i = 0; i < 1; i++)
@ -297,7 +297,7 @@ bench_array()
[array makeObjectsPerformSelector: @selector(hash)];
}
END_TIMER;
PRINT_TIMER("NSArray (once perform)");
PRINT_TIMER("NSArray (once perform)\t\t");
AUTO_END;
}
@ -332,7 +332,7 @@ bench_dict()
}
}
END_TIMER;
PRINT_TIMER("NSDict (1 setObject:) ");
PRINT_TIMER("NSDict (1 setObject:) \t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT; i++)
@ -345,7 +345,7 @@ bench_dict()
}
}
END_TIMER;
PRINT_TIMER("NSDict (10 objectFor:) ");
PRINT_TIMER("NSDict (10 objectFor:) \t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
@ -353,7 +353,7 @@ bench_dict()
[dict count];
}
END_TIMER;
PRINT_TIMER("NSDictionary (10 count)");
PRINT_TIMER("NSDictionary (10 count)\t\t");
obj2 = [dict copy];
START_TIMER;
@ -362,7 +362,7 @@ bench_dict()
[dict isEqual: obj2];
}
END_TIMER;
PRINT_TIMER("NSDict (ten times isEqual:)");
PRINT_TIMER("NSDict (ten times isEqual:)\t\t");
AUTO_END;
}
@ -414,7 +414,7 @@ bench_str()
str = [stringClass stringWithCString: "hello world"];
}
END_TIMER;
PRINT_TIMER("NSString (1 cstring:) ");
PRINT_TIMER("NSString (1 cstring:) \t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
@ -422,7 +422,64 @@ bench_str()
[str length];
}
END_TIMER;
PRINT_TIMER("NSString (10 length) ");
PRINT_TIMER("NSString (10 length) \t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str copy];
}
END_TIMER;
PRINT_TIMER("NSString (10 copy) <initWithCString:> ");
str = @"ConstantString";
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str copy];
}
END_TIMER;
PRINT_TIMER("NSString (10 copy) <@'ConstantString'> ");
str = [[NSString alloc] initWithCStringNoCopy: (char *)[str cString]
length: [str length]
freeWhenDone: NO];
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str copy];
}
END_TIMER;
PRINT_TIMER("NSString (10 copy) <NoCopy:free:NO> ");
str = [[NSString alloc] initWithCStringNoCopy: (char *)[str cString]
length: [str length]
freeWhenDone: YES];
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str copy];
}
END_TIMER;
PRINT_TIMER("NSString (10 copy) <NoCopy:free:YES> ");
str = [stringClass stringWithCString: "hello world"];
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str hash];
}
END_TIMER;
PRINT_TIMER("NSString (10 hash) <initWithCString:> ");
str = @"ConstantString";
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
[str hash];
}
END_TIMER;
PRINT_TIMER("NSString (10 hash) <@'ConstantString'> ");
START_TIMER;
for (i = 0; i < MAX_COUNT/100; i++)
@ -432,7 +489,7 @@ bench_str()
[arp release];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 mkplist) ");
PRINT_TIMER("NSString (1/100 mkplist) \t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT/1000; i++)
@ -440,7 +497,7 @@ bench_str()
[plstr propertyList];
}
END_TIMER;
PRINT_TIMER("NSString (1/1000 plparse)");
PRINT_TIMER("NSString (1/1000 plparse)\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT/1000; i++)
@ -455,7 +512,7 @@ bench_str()
[arp release];
}
END_TIMER;
PRINT_TIMER("NSString (1/1000 plcomp)");
PRINT_TIMER("NSString (1/1000 plcomp)\t\t");
START_TIMER;
for (i = 0; i < MAX_COUNT/100; i++)
@ -464,7 +521,7 @@ bench_str()
[des deserializePropertyListFromData: d mutableContainers: NO];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 ser/des)");
PRINT_TIMER("NSString (1/100 ser/des)\t\t");
[NSDeserializer uniquing: YES];
START_TIMER;
@ -474,7 +531,7 @@ bench_str()
[des deserializePropertyListFromData: d mutableContainers: NO];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 ser/des - uniquing)");
PRINT_TIMER("NSString (1/100 ser/des - uniquing)\t");
[NSDeserializer uniquing: NO];
START_TIMER;
@ -484,7 +541,7 @@ bench_str()
[una unarchiveObjectWithData: d];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 arc/una)");
PRINT_TIMER("NSString (1/100 arc/una)\t\t");
AUTO_END;
}
@ -508,7 +565,7 @@ bench_date()
[d release];
}
END_TIMER;
PRINT_TIMER("NSCalendarDate (various)");
PRINT_TIMER("NSCalendarDate (various)\t\t");
AUTO_END;
}
@ -533,7 +590,7 @@ bench_data()
[d release];
}
END_TIMER;
PRINT_TIMER("NSData (various)");
PRINT_TIMER("NSData (various)\t\t\t");
AUTO_END;
}
@ -553,7 +610,7 @@ int main(int argc, char *argv[], char **env)
stringClass = [NSString class];
pool = [NSAutoreleasePool new];
printf(" Test \t time (sec) \t index\n");
printf(" Test \t\t\t\t time (sec) \t index\n");
bench_object();
bench_str();
bench_array();

175
Testing/exported-strings.m Normal file
View file

@ -0,0 +1,175 @@
/** externs.m Program to test correct initialization of externs.
Copyright (C) 2003 Free Software Foundation, Inc.
Written by: David Ayers <d.ayers@inode.at>
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/Foundation.h>
#include <assert.h>
#define MyAssert1(IDENT) do { \
cache[i++] = IDENT; \
assert (IDENT != 0); \
} while (0)
#define MyAssert2(IDENT) do { \
NSCAssert2([IDENT isEqual: \
[NSString stringWithCString: #IDENT]], \
@"Invalid value: %@ for: %s", \
IDENT, #IDENT); \
NSCAssert2([cache[i++] isEqual: IDENT], \
@"Initial values differ:%@ %@", \
cache[i-1], IDENT); \
} while (0)
#define CACHE_SIZE 256
NSString *cache[CACHE_SIZE];
int
main()
{
NSAutoreleasePool *pool;
int i = 0;
/* Insure extern identifiers are initialized
before ObjC code is executed. */
MyAssert1(NSConnectionDidDieNotification);
MyAssert1(NSConnectionDidInitializeNotification);
MyAssert1(NSWillBecomeMultiThreadedNotification);
MyAssert1(NSThreadDidStartNotification);
MyAssert1(NSThreadWillExitNotification);
// MyAssert1(PortBecameInvalidNotification);
// MyAssert1(InPortClientBecameInvalidNotification);
// MyAssert1(InPortAcceptedClientNotification);
MyAssert1(NSPortDidBecomeInvalidNotification);
MyAssert1(NSConnectionReplyMode);
MyAssert1(NSBundleDidLoadNotification);
MyAssert1(NSShowNonLocalizedStrings);
MyAssert1(NSLoadedClasses);
// MyAssert1(StreamException);
MyAssert1(NSArgumentDomain);
MyAssert1(NSGlobalDomain);
MyAssert1(NSRegistrationDomain);
MyAssert1(NSUserDefaultsDidChangeNotification);
MyAssert1(NSWeekDayNameArray);
MyAssert1(NSShortWeekDayNameArray);
MyAssert1(NSMonthNameArray);
MyAssert1(NSShortMonthNameArray);
MyAssert1(NSTimeFormatString);
MyAssert1(NSDateFormatString);
MyAssert1(NSShortDateFormatString);
MyAssert1(NSTimeDateFormatString);
MyAssert1(NSShortTimeDateFormatString);
MyAssert1(NSCurrencySymbol);
MyAssert1(NSDecimalSeparator);
MyAssert1(NSThousandsSeparator);
MyAssert1(NSInternationalCurrencyString);
MyAssert1(NSCurrencyString);
// MyAssert1(NSNegativeCurrencyFormatString);
// MyAssert1(NSPositiveCurrencyFormatString);
MyAssert1(NSDecimalDigits);
MyAssert1(NSAMPMDesignation);
MyAssert1(NSHourNameDesignations);
MyAssert1(NSYearMonthWeekDesignations);
MyAssert1(NSEarlierTimeDesignations);
MyAssert1(NSLaterTimeDesignations);
MyAssert1(NSThisDayDesignations);
MyAssert1(NSNextDayDesignations);
MyAssert1(NSNextNextDayDesignations);
MyAssert1(NSPriorDayDesignations);
MyAssert1(NSDateTimeOrdering);
MyAssert1(NSLanguageCode);
MyAssert1(NSLanguageName);
MyAssert1(NSFormalName);
MyAssert1(NSLocale);
MyAssert1(NSConnectionRepliesReceived);
MyAssert1(NSConnectionRepliesSent);
MyAssert1(NSConnectionRequestsReceived);
MyAssert1(NSConnectionRequestsSent);
MyAssert1(NSConnectionLocalCount);
MyAssert1(NSConnectionProxyCount);
MyAssert1(NSClassDescriptionNeededForClassNotification);
assert(i < CACHE_SIZE); /* incread the cache size. */
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
pool = [[NSAutoreleasePool alloc] init];
i = 0;
MyAssert2(NSConnectionDidDieNotification);
MyAssert2(NSConnectionDidInitializeNotification);
MyAssert2(NSWillBecomeMultiThreadedNotification);
MyAssert2(NSThreadDidStartNotification);
MyAssert2(NSThreadWillExitNotification);
// MyAssert2(PortBecameInvalidNotification);
// MyAssert2(InPortClientBecameInvalidNotification);
// MyAssert2(InPortAcceptedClientNotification);
MyAssert2(NSPortDidBecomeInvalidNotification);
MyAssert2(NSConnectionReplyMode);
MyAssert2(NSBundleDidLoadNotification);
MyAssert2(NSShowNonLocalizedStrings);
MyAssert2(NSLoadedClasses);
MyAssert2(NSArgumentDomain);
MyAssert2(NSGlobalDomain);
MyAssert2(NSRegistrationDomain);
MyAssert2(NSUserDefaultsDidChangeNotification);
MyAssert2(NSWeekDayNameArray);
MyAssert2(NSShortWeekDayNameArray);
MyAssert2(NSMonthNameArray);
MyAssert2(NSShortMonthNameArray);
MyAssert2(NSTimeFormatString);
MyAssert2(NSDateFormatString);
MyAssert2(NSShortDateFormatString);
MyAssert2(NSTimeDateFormatString);
MyAssert2(NSShortTimeDateFormatString);
MyAssert2(NSCurrencySymbol);
MyAssert2(NSDecimalSeparator);
MyAssert2(NSThousandsSeparator);
MyAssert2(NSInternationalCurrencyString);
MyAssert2(NSCurrencyString);
// MyAssert2(NSNegativeCurrencyFormatString);
// MyAssert2(NSPositiveCurrencyFormatString);
MyAssert2(NSDecimalDigits);
MyAssert2(NSAMPMDesignation);
MyAssert2(NSHourNameDesignations);
MyAssert2(NSYearMonthWeekDesignations);
MyAssert2(NSEarlierTimeDesignations);
MyAssert2(NSLaterTimeDesignations);
MyAssert2(NSThisDayDesignations);
MyAssert2(NSNextDayDesignations);
MyAssert2(NSNextNextDayDesignations);
MyAssert2(NSPriorDayDesignations);
MyAssert2(NSDateTimeOrdering);
MyAssert2(NSLanguageCode);
MyAssert2(NSLanguageName);
MyAssert2(NSFormalName);
MyAssert2(NSLocale);
MyAssert2(NSConnectionRepliesReceived);
MyAssert2(NSConnectionRepliesSent);
MyAssert2(NSConnectionRequestsReceived);
MyAssert2(NSConnectionRequestsSent);
MyAssert2(NSConnectionLocalCount);
MyAssert2(NSConnectionProxyCount);
MyAssert2(NSClassDescriptionNeededForClassNotification);
[pool release];
exit(0);
}