I would think any speed difference would be negligible, considering all that happens when an object is created. Not only do the fields need to be initialized, but the New() method needs to be processed (even if your type doesn't have a New() method, the base Object type does), the reference needs to be added to the GC, etc...
I guess that tests could be run to figure it out
Just ran some tests of my own.
first run:
second run:
Third Run:
The first run defines nothing and leaves the compiler to use defaults. The second run sets everything to defualt values explicitly (0.0 and Null), the third run defines non default values and does a New TTest for the field in TTest2
results
First run:
2531
2505
Second Run:
2516
2545
Third run:
2666
4907
As you can see, there is not any huge difference in the times except when an embedded type is initialized to an actual type and not Null. And even then, it is proportionately double which is consistent of having to initialize two different types at once.
I guess that tests could be run to figure it out
Just ran some tests of my own.
first run:
SuperStrict Type TTest Field x:Int Field y:Int Field MyFloat:Float Field MyDouble:Double Field MyString:String End Type Type TTest2 Field X:Int Field Y:Long Field Z:TTest End Type Local Test:TTest Local Test2:TTest2 Local Time:Int Delay (1000) Time = MilliSecs() For Local i:Int = 1 To 10000000 Test = New TTest Next Time = MilliSecs() - Time Print Time Time = MilliSecs() For Local i:Int = 1 To 10000000 Test2 = New TTest2 Next Time = MilliSecs() - Time Print Time
second run:
SuperStrict Type TTest Field x:Int = 0 Field y:Int = 0 Field MyFloat:Float = 0.0 Field MyDouble:Double = 0.0 Field MyString:String = Null End Type Type TTest2 Field X:Int = 0 Field Y:Long = 0 Field Z:TTest = Null End Type Local Test:TTest Local Test2:TTest2 Local Time:Int Delay (1000) Time = MilliSecs() For Local i:Int = 1 To 10000000 Test = New TTest Next Time = MilliSecs() - Time Print Time Time = MilliSecs() For Local i:Int = 1 To 10000000 Test2 = New TTest2 Next Time = MilliSecs() - Time Print Time
Third Run:
SuperStrict Type TTest Field x:Int = 5 Field y:Int = 18 Field MyFloat:Float = 7.6 Field MyDouble:Double = 5.5 Field MyString:String = "hello" End Type Type TTest2 Field X:Int = 3 Field Y:Long = 7 Field Z:TTest = New TTest End Type Local Test:TTest Local Test2:TTest2 Local Time:Int Delay (1000) Time = MilliSecs() For Local i:Int = 1 To 10000000 Test = New TTest Next Time = MilliSecs() - Time Print Time Time = MilliSecs() For Local i:Int = 1 To 10000000 Test2 = New TTest2 Next Time = MilliSecs() - Time Print Time
The first run defines nothing and leaves the compiler to use defaults. The second run sets everything to defualt values explicitly (0.0 and Null), the third run defines non default values and does a New TTest for the field in TTest2
results
First run:
2531
2505
Second Run:
2516
2545
Third run:
2666
4907
As you can see, there is not any huge difference in the times except when an embedded type is initialized to an actual type and not Null. And even then, it is proportionately double which is consistent of having to initialize two different types at once.