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: Marcel Weiher <email@hidden>
- Date: Thu, 25 Jul 2002 17:02:14 +0200
On Thursday, July 25, 2002, at 04:28 Uhr, Philip George wrote:
But I know for a fact that I have clearly observed
dynamic typing taking longer at runtime with LOTS of objects.
No. You probably have seen *something*, but it was something else.
Both generate the exact same code. There can be no difference.
It is subtle by most people's terms, but I think static typing is still
winning here.
No, because you are measuring other things, primarily drawing.
I don't have time to mess with this too much longer, but I'm going to
try one more test. I'm going to create and array of a few thousand
NSTextFields and I'm going to test it with only dynamic typing for 10
runs and then and then recompile with static typing only and rerun 10
times. That way caching isn't even in the picture.
Don't use complex objects. Use something simple. Like the following.
It shows that two programs that differ only in their use of static
typing produce the exact same code when compiled and the same timing
results. They both send an instance of NSObject the message "class" 100
million times (in order to get reasonably measurable results).
QED,
Marcel
marcel@tuvuk[/tmp]cat testdynamic.m
#import <Foundation/Foundation.h>
int main( int argc, char *argv[] )
{
id hi=[NSObject new];
int i;
for (i=0;i<100000000;i++) {
[hi class];
}
return 0;
}
marcel@tuvuk[/tmp]cat teststatic.m
#import <Foundation/Foundation.h>
int main( int argc, char *argv[] )
{
NSObject* hi=[NSObject new];
int i;
for (i=0;i<100000000;i++) {
[hi class];
}
return 0;
}
marcel@tuvuk[/tmp]diff testdynamic.m teststatic.m
6c6
< id hi=[NSObject new];
---
> NSObject* hi=[NSObject new];
marcel@tuvuk[/tmp]cc -O -Wall -o teststatic teststatic.m -framework
Foundation
marcel@tuvuk[/tmp]cc -O -Wall -o testdynamic testdynamic.m -framework
Foundation
marcel@tuvuk[/tmp]time ./testdynamic
real 0m5.981s
user 0m5.830s
sys 0m0.030s
marcel@tuvuk[/tmp]time ./teststatic
real 0m5.972s
user 0m5.860s
sys 0m0.040s
marcel@tuvuk[/tmp]cc -O -Wall -S testdynamic.m
marcel@tuvuk[/tmp]cc -O -Wall -S teststatic.m
marcel@tuvuk[/tmp]diff teststatic.s testdynamic.s
90c90
< .ascii "teststatic.m\000"
---
> .ascii "testdynamic.m\000"
marcel@tuvuk[/tmp]cat teststatic.s
.macro mul
mul$0 $1,$2,$3
.endmacro
.macro div
div$0 $1,$2,$3
.endmacro
.text
.align 2
.globl _main
_main:
mflr r0
stmw r28,-16(r1)
stw r0,8(r1)
stwu r1,-80(r1)
bcl 20,31,L1$pb
L1$pb:
mflr r31
addis r3,r31,ha16(L_OBJC_CLASS_REFERENCES_0-L1$pb)
addis r4,r31,ha16(L_OBJC_SELECTOR_REFERENCES_0-L1$pb)
lwz r3,lo16(L_OBJC_CLASS_REFERENCES_0-L1$pb)(r3)
lwz r4,lo16(L_OBJC_SELECTOR_REFERENCES_0-L1$pb)(r4)
bl L_objc_msgSend$stub
mr r29,r3
li r30,0
lis r28,0x5f5
ori r28,r28,57599
L6:
addis r4,r31,ha16(L_OBJC_SELECTOR_REFERENCES_1-L1$pb)
mr r3,r29
lwz r4,lo16(L_OBJC_SELECTOR_REFERENCES_1-L1$pb)(r4)
bl L_objc_msgSend$stub
addi r30,r30,1
cmpw cr0,r30,r28
bc 4,1,L6
li r3,0
lwz r0,88(r1)
la r1,80(r1)
mtlr r0
lmw r28,-16(r1)
blr
.objc_cat_cls_meth
.objc_cat_inst_meth
.objc_string_object
.section __OBJC, __cstring_object
.objc_message_refs
.section __OBJC, __sel_fixup
.objc_cls_refs
.objc_class
.objc_meta_class
.objc_cls_meth
.objc_inst_meth
.objc_protocol
.objc_class_names
.objc_meth_var_types
.objc_meth_var_names
.objc_category
.objc_class_vars
.objc_instance_vars
.objc_module_info
.objc_symbols
.objc_symbols
.align 2
L_OBJC_SYMBOLS:
.long 0
.long 0
.short 0
.short 0
.objc_message_refs
.align 2
L_OBJC_SELECTOR_REFERENCES_0:
.long L_OBJC_METH_VAR_NAME_0
.align 2
L_OBJC_SELECTOR_REFERENCES_1:
.long L_OBJC_METH_VAR_NAME_1
.objc_module_info
.align 2
L_OBJC_MODULES:
.long 5
.long 16
.long L_OBJC_CLASS_NAME_0
.long L_OBJC_SYMBOLS
.lazy_reference .objc_class_name_NSObject
.objc_cls_refs
.align 2
L_OBJC_CLASS_REFERENCES_0:
.long L_OBJC_CLASS_NAME_1
.objc_class_names
.align 2
L_OBJC_CLASS_NAME_0:
.ascii "teststatic.m\000"
.align 2
L_OBJC_CLASS_NAME_1:
.ascii "NSObject\000"
.objc_meth_var_names
.align 2
L_OBJC_METH_VAR_NAME_0:
.ascii "new\000"
.align 2
L_OBJC_METH_VAR_NAME_1:
.ascii "class\000"
.picsymbol_stub
L_objc_msgSend$stub:
.indirect_symbol _objc_msgSend
mflr r0
bcl 20,31,L2$pb
L2$pb:
mflr r11
addis r11,r11,ha16(L2$lz-L2$pb)
mtlr r0
lwz r12,lo16(L2$lz-L2$pb)(r11)
mtctr r12
addi r11,r11,lo16(L2$lz-L2$pb)
bctr
.lazy_symbol_pointer
L2$lz:
.indirect_symbol _objc_msgSend
.long dyld_stub_binding_helper
marcel@tuvuk[/tmp]cat testdynamic.s
.macro mul
mul$0 $1,$2,$3
.endmacro
.macro div
div$0 $1,$2,$3
.endmacro
.text
.align 2
.globl _main
_main:
mflr r0
stmw r28,-16(r1)
stw r0,8(r1)
stwu r1,-80(r1)
bcl 20,31,L1$pb
L1$pb:
mflr r31
addis r3,r31,ha16(L_OBJC_CLASS_REFERENCES_0-L1$pb)
addis r4,r31,ha16(L_OBJC_SELECTOR_REFERENCES_0-L1$pb)
lwz r3,lo16(L_OBJC_CLASS_REFERENCES_0-L1$pb)(r3)
lwz r4,lo16(L_OBJC_SELECTOR_REFERENCES_0-L1$pb)(r4)
bl L_objc_msgSend$stub
mr r29,r3
li r30,0
lis r28,0x5f5
ori r28,r28,57599
L6:
addis r4,r31,ha16(L_OBJC_SELECTOR_REFERENCES_1-L1$pb)
mr r3,r29
lwz r4,lo16(L_OBJC_SELECTOR_REFERENCES_1-L1$pb)(r4)
bl L_objc_msgSend$stub
addi r30,r30,1
cmpw cr0,r30,r28
bc 4,1,L6
li r3,0
lwz r0,88(r1)
la r1,80(r1)
mtlr r0
lmw r28,-16(r1)
blr
.objc_cat_cls_meth
.objc_cat_inst_meth
.objc_string_object
.section __OBJC, __cstring_object
.objc_message_refs
.section __OBJC, __sel_fixup
.objc_cls_refs
.objc_class
.objc_meta_class
.objc_cls_meth
.objc_inst_meth
.objc_protocol
.objc_class_names
.objc_meth_var_types
.objc_meth_var_names
.objc_category
.objc_class_vars
.objc_instance_vars
.objc_module_info
.objc_symbols
.objc_symbols
.align 2
L_OBJC_SYMBOLS:
.long 0
.long 0
.short 0
.short 0
.objc_message_refs
.align 2
L_OBJC_SELECTOR_REFERENCES_0:
.long L_OBJC_METH_VAR_NAME_0
.align 2
L_OBJC_SELECTOR_REFERENCES_1:
.long L_OBJC_METH_VAR_NAME_1
.objc_module_info
.align 2
L_OBJC_MODULES:
.long 5
.long 16
.long L_OBJC_CLASS_NAME_0
.long L_OBJC_SYMBOLS
.lazy_reference .objc_class_name_NSObject
.objc_cls_refs
.align 2
L_OBJC_CLASS_REFERENCES_0:
.long L_OBJC_CLASS_NAME_1
.objc_class_names
.align 2
L_OBJC_CLASS_NAME_0:
.ascii "testdynamic.m\000"
.align 2
L_OBJC_CLASS_NAME_1:
.ascii "NSObject\000"
.objc_meth_var_names
.align 2
L_OBJC_METH_VAR_NAME_0:
.ascii "new\000"
.align 2
L_OBJC_METH_VAR_NAME_1:
.ascii "class\000"
.picsymbol_stub
L_objc_msgSend$stub:
.indirect_symbol _objc_msgSend
mflr r0
bcl 20,31,L2$pb
L2$pb:
mflr r11
addis r11,r11,ha16(L2$lz-L2$pb)
mtlr r0
lwz r12,lo16(L2$lz-L2$pb)(r11)
mtctr r12
addi r11,r11,lo16(L2$lz-L2$pb)
bctr
.lazy_symbol_pointer
L2$lz:
.indirect_symbol _objc_msgSend
.long dyld_stub_binding_helper
marcel@tuvuk[/tmp]
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.