Re: What is the purpose of static typing?
Re: What is the purpose of static typing?
- Subject: Re: What is the purpose of static typing?
- From: Sylvain Leroux <email@hidden>
- Date: Thu, 25 Jul 2002 17:41:43 +0200
Note that the 'id' window didn't beat the statically-typed window even
once. They came close sometimes, but static typing always won.
Usually you wouldn't notice, because it might just be a couple little
objects, but I am talking about when you mass produce objects as id.
That's strange... Try this:
#import <Foundation/Foundation.h>
@interface BenO : NSObject {
}
- (void)doSomeStuff;
@end
static long count = 0;
@implementation BenO
- (void)doSomeStuff
{
count++;
}
@end
#if 1
#define TYPE id
#define MESSAGE @"Dynamic"
#else
#define TYPE BenO*
#define MESSAGE @"Static"
#endif
TYPE makeAnObject(void)
{
return [[BenO alloc] init];
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
TYPE object = makeAnObject();
unsigned i;
clock_t start;
clock_t end;
// insert code here...
NSLog(@"%@ Test", MESSAGE);
start = clock();
for(i = 0; i < 10000000; ++i)
{
[object retain];
[object doSomeStuff];
[object release];
}
end = clock();
NSLog(@"\n\t%d ticks", end-start);
[pool release];
return 0;
}
By replacing the '#if 1' statement by '#if 0' you switch from dynamic to
static typing. I've run both versions of this tool a couple of times and
the results are always the same:
2002-07-25 17:24:43.492 Bench[1828] Dynamic Test
2002-07-25 17:24:59.722 Bench[1828]
1519 ticks
Bench has exited with status 0.
versus
2002-07-25 17:32:02.728 Bench[1848] Static Test
2002-07-25 17:32:18.806 Bench[1848]
1519 ticks
Bench has exited with status 0.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.