1998-11-12 08:40:01 +00:00
|
|
|
/* Simple benchmark program.
|
|
|
|
Copyright (C) 1998 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Modified: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
2001-04-22 14:57:20 +00:00
|
|
|
Modified: Nicola Pero <n.pero@mi.flashnet.it>
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
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
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <objc/Object.h>
|
|
|
|
|
|
|
|
#define MAX_COUNT 100000
|
|
|
|
|
|
|
|
#define START_TIMER sTime = [NSDate date]
|
|
|
|
#define END_TIMER eTime = [NSDate date]
|
|
|
|
#define PRINT_TIMER(str) printf(" %-20s\t %6.3f \t %6.3f\n", str, \
|
|
|
|
[eTime timeIntervalSinceDate: sTime], \
|
|
|
|
[eTime timeIntervalSinceDate: sTime]/baseline)
|
2001-10-30 16:14:44 +00:00
|
|
|
#define PRINT_TIMER_NO_BASELINE(str) \
|
|
|
|
printf(" %-20s\t %6.3f \t %6.3f\n", str, \
|
|
|
|
[eTime timeIntervalSinceDate: sTime] - baseline, \
|
|
|
|
[eTime timeIntervalSinceDate: sTime]/baseline - 1)
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
#define AUTO_START id pool = [NSAutoreleasePool new]
|
|
|
|
#define AUTO_END [pool release]
|
|
|
|
|
|
|
|
NSDate *sTime = nil;
|
|
|
|
NSDate *eTime = nil;
|
|
|
|
/* Set to a baseline to null out speed of runtime */
|
|
|
|
NSTimeInterval baseline = 0.0;
|
|
|
|
|
|
|
|
NSZone *myZone;
|
|
|
|
Class rootClass;
|
|
|
|
Class stringClass;
|
|
|
|
IMP cstring;
|
|
|
|
|
2001-10-30 16:14:44 +00:00
|
|
|
@interface MyObject : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MyObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MyObject (Category)
|
|
|
|
- (id) self
|
|
|
|
{
|
|
|
|
return [super self];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
void
|
|
|
|
bench_object()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
id obj;
|
2001-04-22 14:57:20 +00:00
|
|
|
objc_mutex_t mutex;
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_START;
|
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[rootClass class];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
|
|
|
baseline = [eTime timeIntervalSinceDate: sTime];
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Baseline: 10 method calls\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
1999-01-08 09:48:33 +00:00
|
|
|
START_TIMER;
|
2001-04-23 22:37:51 +00:00
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
1999-01-08 09:48:33 +00:00
|
|
|
{
|
2001-04-23 22:37:51 +00:00
|
|
|
/* Ten class methods with the more common class names */
|
|
|
|
id i;
|
|
|
|
i = [NSObject class];
|
|
|
|
i = [NSString class];
|
|
|
|
i = [NSDictionary class];
|
|
|
|
i = [NSArray class];
|
|
|
|
i = [NSData class];
|
|
|
|
i = [NSUserDefaults class];
|
|
|
|
i = [NSMutableArray class];
|
|
|
|
i = [NSFileManager class];
|
|
|
|
i = [NSMutableString class];
|
|
|
|
i = [NSMutableDictionary class];
|
1999-01-08 09:48:33 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Class: 10 class method calls\t\t");
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-10-30 16:14:44 +00:00
|
|
|
obj = [MyObject new];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-10-30 16:14:44 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT * 10; i++)
|
|
|
|
{
|
|
|
|
id i;
|
|
|
|
i = [obj self];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER_NO_BASELINE("Category: 10 super calls\t\t");
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-04-23 22:37:51 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
/* Corresponding look ups */
|
|
|
|
id i;
|
|
|
|
i = NSClassFromString (@"NSObject");
|
|
|
|
i = NSClassFromString (@"NSString");
|
|
|
|
i = NSClassFromString (@"NSDictionary");
|
|
|
|
i = NSClassFromString (@"NSArray");
|
|
|
|
i = NSClassFromString (@"NSData");
|
|
|
|
i = NSClassFromString (@"NSUserDefaults");
|
|
|
|
i = NSClassFromString (@"NSMutableArray");
|
|
|
|
i = NSClassFromString (@"NSFileManager");
|
|
|
|
i = NSClassFromString (@"NSMutableString");
|
|
|
|
i = NSClassFromString (@"NSMutableDictionary");
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Function: 10 NSClassFromStr\t\t");
|
1999-01-08 09:48:33 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
START_TIMER;
|
|
|
|
myZone = NSCreateZone(2048, 2048, 1);
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
void *mem = NSZoneMalloc(myZone, 32);
|
|
|
|
NSZoneFree(myZone, mem);
|
|
|
|
}
|
|
|
|
NSRecycleZone(myZone);
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Function: 1 zone alloc/free\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
myZone = NSCreateZone(2048, 2048, 0);
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
void *mem = NSZoneMalloc(myZone, 32);
|
|
|
|
NSZoneFree(myZone, mem);
|
|
|
|
}
|
|
|
|
NSRecycleZone(myZone);
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Function: 1 zone2alloc/free\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
myZone = NSDefaultMallocZone();
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
void *mem = NSZoneMalloc(myZone, 32);
|
|
|
|
NSZoneFree(myZone, mem);
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("Function: 1 def alloc/free\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
myZone = NSCreateZone(2048, 2048, 1);
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
obj = [[rootClass allocWithZone: myZone] init];
|
|
|
|
[obj release];
|
|
|
|
}
|
|
|
|
NSRecycleZone(myZone);
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSObject: 1 zone all/init/rel\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
myZone = NSCreateZone(2048, 2048, 0);
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
obj = [[rootClass allocWithZone: myZone] init];
|
|
|
|
[obj release];
|
|
|
|
}
|
|
|
|
NSRecycleZone(myZone);
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSObject: 1 zone2all/init/rel\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
myZone = NSDefaultMallocZone();
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
obj = [[rootClass allocWithZone: myZone] init];
|
|
|
|
[obj release];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSObject: 1 def all/init/rel\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
|
|
|
|
obj = [rootClass new];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
|
|
|
[obj retain];
|
|
|
|
[obj release];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSObject: 10 retain/rel\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
[obj release];
|
|
|
|
|
|
|
|
obj = [rootClass new];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
|
|
|
[obj autorelease];
|
|
|
|
[obj retain];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSObject: 10 autorel/ret\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
[obj release];
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[rootClass instancesRespondToSelector: @selector(hash)];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("ObjC: 10 inst responds to sel\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
|
|
|
|
mutex = objc_mutex_allocate();
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
|
|
|
objc_mutex_lock(mutex);
|
|
|
|
objc_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("ObjC: 10 objc_mutex_lock/unl\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
objc_mutex_deallocate(mutex);
|
|
|
|
|
|
|
|
obj = [NSLock new];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
|
|
|
[obj lock];
|
|
|
|
[obj unlock];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSLock: 10 lock/unlock\t\t");
|
2001-04-22 14:57:20 +00:00
|
|
|
[obj release];
|
1998-11-12 08:40:01 +00:00
|
|
|
|
2001-04-23 22:37:51 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
2002-02-25 15:04:06 +00:00
|
|
|
void
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_array()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
id array;
|
|
|
|
NSString *strings[MAX_COUNT];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_START;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
char buf1[100];
|
|
|
|
sprintf(buf1, "str%0d", i);
|
|
|
|
strings[i] = [stringClass stringWithCString: buf1];
|
|
|
|
}
|
|
|
|
printf("NSArray\n");
|
|
|
|
array = [NSMutableArray arrayWithCapacity: 16];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
|
|
|
[array addObject: strings[i/10]];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSArray (10 addObject:)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
[array indexOfObject: strings[i]];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSArray (1/100 indexOfObj)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
1998-11-14 03:48:19 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
[array indexOfObjectIdenticalTo: strings[i]];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSArray (1/100 indexIdent)\t\t");
|
1998-11-14 03:48:19 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < 1; i++)
|
|
|
|
{
|
1998-11-14 03:48:19 +00:00
|
|
|
[array makeObjectsPerformSelector: @selector(hash)];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSArray (once perform)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
2002-02-25 15:04:06 +00:00
|
|
|
void
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_dict()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSMutableDictionary *dict;
|
|
|
|
id obj2;
|
|
|
|
NSString *keys[MAX_COUNT/10];
|
|
|
|
NSString *vals[MAX_COUNT/10];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_START;
|
|
|
|
for (i = 0; i < MAX_COUNT/10; i++)
|
|
|
|
{
|
|
|
|
char buf1[100], buf2[100];
|
|
|
|
sprintf(buf1, "key%0d", i);
|
|
|
|
sprintf(buf2, "val%0d", i);
|
|
|
|
keys[i] = [stringClass stringWithCString: buf1];
|
|
|
|
vals[i] = [stringClass stringWithCString: buf2];
|
|
|
|
}
|
|
|
|
printf("NSDictionary\n");
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 16];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/10; i++)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 10; j++)
|
|
|
|
{
|
|
|
|
[dict setObject: vals[i] forKey: keys[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSDict (1 setObject:) \t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 10; j++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[dict objectForKey: keys[i/10]];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSDict (10 objectFor:) \t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[dict count];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSDictionary (10 count)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
obj2 = [dict copy];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[dict isEqual: obj2];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSDict (ten times isEqual:)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
2002-02-25 15:04:06 +00:00
|
|
|
void
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_str()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSString *str;
|
2004-05-14 10:52:30 +00:00
|
|
|
NSMutableString *ms;
|
1998-11-12 08:40:01 +00:00
|
|
|
id plist;
|
|
|
|
NSString *plstr;
|
1998-11-19 15:49:43 +00:00
|
|
|
Class arc = [NSArchiver class];
|
|
|
|
Class una = [NSUnarchiver class];
|
|
|
|
Class ser = [NSSerializer class];
|
|
|
|
Class des = [NSDeserializer class];
|
|
|
|
Class md = [NSMutableDictionary class];
|
2002-10-15 04:55:51 +00:00
|
|
|
AUTO_START;
|
1998-11-12 08:40:01 +00:00
|
|
|
|
2002-09-30 16:54:29 +00:00
|
|
|
[[md new] release];
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
plist = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"Value1", @"Key1",
|
|
|
|
@"", @"Key2",
|
|
|
|
[NSArray array], @"Key3",
|
|
|
|
[NSArray arrayWithObjects:
|
|
|
|
@"Array1 entry1",
|
|
|
|
@"Array1 entry2",
|
|
|
|
[NSArray arrayWithObjects:
|
|
|
|
@"Array2 entry1",
|
|
|
|
@"Array2 entry2",
|
|
|
|
nil],
|
|
|
|
[NSDictionary dictionary],
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"Value", @"Key",
|
|
|
|
nil],
|
|
|
|
nil], @"Key4",
|
|
|
|
[NSDictionary dictionary], @"Key5",
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"Value", @"Key",
|
|
|
|
nil], @"Key6",
|
|
|
|
[NSData data], @"Key7",
|
|
|
|
[NSData dataWithBytes: "hello" length: 5], @"Key8",
|
|
|
|
nil];
|
|
|
|
plstr = [plist description];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
printf("NSString\n");
|
2004-05-14 10:52:30 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
str = [[stringClass alloc] initWithFormat: @"Hello %d", i];
|
|
|
|
RELEASE(str);
|
|
|
|
}
|
|
|
|
END_TIMER;
|
|
|
|
PRINT_TIMER("NSString (1 initWithFormat:) \t");
|
|
|
|
|
|
|
|
ms = [NSMutableString stringWithCapacity: 0];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
[ms appendFormat: @"%d", i];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
|
|
|
PRINT_TIMER("NSString (1 appendFormat:) \t\t");
|
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT; i++)
|
|
|
|
{
|
|
|
|
str = [stringClass stringWithCString: "hello world"];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1 cstring:) \t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT*10; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[str length];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
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'> ");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
id arp = [NSAutoreleasePool new];
|
2002-09-30 16:54:29 +00:00
|
|
|
[plist description];
|
1998-11-12 08:40:01 +00:00
|
|
|
[arp release];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/100 mkplist) \t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/1000; i++)
|
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
[plstr propertyList];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/1000 plparse)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/1000; i++)
|
|
|
|
{
|
|
|
|
id arp = [NSAutoreleasePool new];
|
|
|
|
NSString *s = [plist description];
|
|
|
|
id p = [s propertyList];
|
|
|
|
if ([p isEqual: plist] == NO)
|
|
|
|
printf("Argh 1\n");
|
|
|
|
if ([s isEqual: plstr] == NO)
|
|
|
|
printf("Argh 2\n");
|
|
|
|
[arp release];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/1000 plcomp)\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
|
1998-11-19 15:49:43 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
NSData *d = [ser serializePropertyList: plist];
|
2002-09-30 16:54:29 +00:00
|
|
|
[des deserializePropertyListFromData: d mutableContainers: NO];
|
1998-11-19 15:49:43 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/100 ser/des)\t\t");
|
1998-11-19 15:49:43 +00:00
|
|
|
|
2000-04-18 09:02:38 +00:00
|
|
|
[NSDeserializer uniquing: YES];
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
NSData *d = [ser serializePropertyList: plist];
|
2002-09-30 16:54:29 +00:00
|
|
|
[des deserializePropertyListFromData: d mutableContainers: NO];
|
2000-04-18 09:02:38 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/100 ser/des - uniquing)\t");
|
2000-04-18 09:02:38 +00:00
|
|
|
[NSDeserializer uniquing: NO];
|
|
|
|
|
1998-11-19 15:49:43 +00:00
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/100; i++)
|
|
|
|
{
|
|
|
|
NSData *d = [arc archivedDataWithRootObject: plist];
|
2002-09-30 16:54:29 +00:00
|
|
|
[una unarchiveObjectWithData: d];
|
1998-11-19 15:49:43 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSString (1/100 arc/una)\t\t");
|
1998-11-19 15:49:43 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
2002-09-30 16:54:29 +00:00
|
|
|
void
|
|
|
|
bench_date()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
id d;
|
|
|
|
AUTO_START;
|
|
|
|
Class dateClass = [NSCalendarDate class];
|
|
|
|
|
|
|
|
printf("NSCalendarDate\n");
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/10; i++)
|
2005-02-22 11:22:44 +00:00
|
|
|
{
|
2002-09-30 16:54:29 +00:00
|
|
|
d = [[dateClass alloc] init];
|
|
|
|
[d description];
|
|
|
|
[d dayOfYear];
|
|
|
|
[d minuteOfHour];
|
|
|
|
[d release];
|
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSCalendarDate (various)\t\t");
|
2002-09-30 16:54:29 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
2002-02-25 15:04:06 +00:00
|
|
|
void
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_data()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
id d, o;
|
|
|
|
AUTO_START;
|
|
|
|
Class dataClass = [NSData class];
|
|
|
|
|
|
|
|
printf("NSData\n");
|
|
|
|
START_TIMER;
|
|
|
|
for (i = 0; i < MAX_COUNT/10; i++)
|
2005-02-22 11:22:44 +00:00
|
|
|
{
|
1999-05-19 20:18:51 +00:00
|
|
|
d = [[dataClass alloc] initWithContentsOfFile:@"benchmark.m"];
|
1998-11-12 08:40:01 +00:00
|
|
|
[d length];
|
|
|
|
o = [d copy];
|
|
|
|
[o release];
|
|
|
|
o = [d mutableCopy];
|
|
|
|
[o release];
|
1999-05-19 20:18:51 +00:00
|
|
|
[d release];
|
1998-11-12 08:40:01 +00:00
|
|
|
}
|
|
|
|
END_TIMER;
|
2003-11-06 21:11:39 +00:00
|
|
|
PRINT_TIMER("NSData (various)\t\t\t");
|
1998-11-12 08:40:01 +00:00
|
|
|
AUTO_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[], char **env)
|
|
|
|
{
|
|
|
|
id pool;
|
|
|
|
|
2000-06-30 22:42:48 +00:00
|
|
|
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
1998-11-12 08:40:01 +00:00
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2005-02-22 11:22:44 +00:00
|
|
|
* Cache classes to remove overhead of objc runtime class lookup from
|
1998-11-12 08:40:01 +00:00
|
|
|
* the benchmark.
|
|
|
|
*/
|
|
|
|
rootClass = [NSObject class];
|
|
|
|
stringClass = [NSString class];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1998-11-12 08:40:01 +00:00
|
|
|
pool = [NSAutoreleasePool new];
|
2003-11-06 21:11:39 +00:00
|
|
|
printf(" Test \t\t\t\t time (sec) \t index\n");
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_object();
|
|
|
|
bench_str();
|
|
|
|
bench_array();
|
|
|
|
bench_dict();
|
2002-09-30 16:54:29 +00:00
|
|
|
bench_date();
|
1998-11-12 08:40:01 +00:00
|
|
|
bench_data();
|
|
|
|
AUTO_END;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|