Structure constructor in .net: any overhead? -


Regarding the use of constructors; Are those two code blocks similar in display?

with constructor

 for point of point for point I = integers = 1 to 1000 pt = new point (i, i) next 

Not Manufacturer:

 As an integer for DM point point = 1 to 1000 pt.X = i pt.Y = i Next 

First one is less, especially if the constructor There will be more logic, but is it wise to use it in the loop (say that Game Loop has been removed from 60 seconds per second)? Or are they two machines compiled for the same machine code?

The time of this code is not actually possible. If you run the release version of the code, you will only get realistic timing results. Whichever kicks in the JIT adapter and it is quite sensible that "PT" is not actually used anywhere, all these codes Which specifies it you will end up with the exact same time and still do not know anything.

To actually throw the assignment code to the JIT adapter, you have to do something with "pt". Such as:

  console. Published (pt)  

But now you will tell about time how many times the console was released () Instead of the efficiency of the assignment. In this case, what is worthy is to look at the generated machine code though. Here's an annotated version of My X86 JIT Compiler, which has a built-in release build with an optimized adapter:

  00000008 xor eax, eax; New Point 0000000a mov dword ptr [ebp-10h], xxx; Pt.X = 0 0000000d mov dword ptr [ebp-0Ch], xxx; Pt.Y = 0 [first piece] 00000010 mov esi, 1; I = 1 pt = new point (i, i) 00000015 mov dword ptr [ebp-10h], esi; Pt.X = i 00000018 mov dword ptr [ebp-0Ch], esi; Pt.Y = i [elided] 00000036 esi, 1; I = i + 1 00000039 Which is 0000007D; Overflow check 0000003 B CMP SEI, 3E8H; I & lt; = 1000? 00000041 Jale 00000015; Yes: loop [second piece] 00000043 mov esi, 1; I = 1 pt.x = i 00000048 mov dword ptr [ebp-10h], esi; Pt.X = i pt.Y = i 0000004b mov dword ptr [ebp-0Ch], esi; Pt.Y = i [elided] 00000069 esi, 1; I = i + 1 0000006C which is 0000007D; Overflow check 0000006e CMP SEI, 3E8H; I & lt; = 1000? 00000074 Jale 00000048: Yes: Loop  

[elided] is the section console. Observe the WrightLine () call machine code instructions closely:

This is exactly the same code .

JIT compiler is good. If you call it to do the same thing, then it generates the same code. Generic code is the code for clarity rather than efficiency, although such statements are often not verified, it is often accurate.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -