Tag:c# vb.net performance
VB.net vs C #, second wave: efficiency collisions from the point of view of efficiency, all. NET performance is the same? The answer may be a surprise to you. See what we found when we looked at the code at a deep level. If all new technologies share an attribute in childhood, that's a whole bunch of questions. Microsoft's new. NET Development framework is the same. So we decided to build a district here specifically to answer about. NET development issues. So if you have any questions about Microsoft's new development platform, I'll try to fix it, despite sending the problem. We received a question about performance, a question from Vladimir Srecovic. C # Performance Benchmark Q: I've seen reports of C # producing IL (intermediate language) code that is faster than the code generated by vb.net, is it true? A: My answer to this question is no, and I have never seen any evidence that C # has an advantage in speed and that it is impossible to have any significant performance differences. After all, IL code is compiled into natural code by the same JIT compiler, ignoring which Il compiler is generated. So at least in theory, as long as your IL compiler conforms to the standard, the equivalent vb.net,c# or even the Cobol.net code will be compiled into the same IL code as the basic one. In any case, these are traditional ideas. To prove it more thoroughly, I decided to use a small experiment to see if it was reasonable. I chose the vb.net and C # versions of the TypeFinder sample application (in \program Files\microsoft.net\frameworksdk\samples\applications\ TypeFinder) and compile them. Next, I select the result to execute the file and view the IL generated by the two compilers through the MSIL Disassembler utility (\program Files\microsoft.net\frameworksdk\bin\ildasm.exe). Then I compare the IL produced by these two pieces specifically for a fairly simple method indentedwriter.writeline. You can see figure a vb.net source of this method, C # source in Figure B.
Figure A VB. NET version is a little bit longer than the C # version.
Figure B C # version uses 7 lines of code. When I compared the final IL code, I was surprised by what I found: the vb.net version is 9 lines longer than the C # version (and 9KB). You can see in list A that the results of the il;c# compiler produced by the vb.net compiler appear in List B. List A:
. method public Hidebysig instance void WriteLine (String message) cil managed {//Code size (0x4b). maxstack 3. Locals init ([0] int32 I, [1] class [mscorlib]System.Text.StringBuilder SB, [2] int32 _vb_t_i4_0) IL_0000:NOP il_0001:ldarg.0 il_0002:ldfld bool Netsdksamples.indentedwriter::myprintflag il_0007:brfalse. s il_0048 il_0009:newobj instance void [Mscorlib]system.text.stringbuilder::.ctor () il_000e:stloc.1 IL_000f: ldc.i4.0 il_0010:ldarg.0 il_0011:ldfld int32 netsdksamples.indentedwriter::myindent il_0016:ldc.i4.1 IL_001 7:SUB.OVF il_0018:stloc.2 il_0019:stloc.0 il_001a:br.s il_002a il_001c:ldloc.1 il_001d:ldc.i4.s 3 2 Il_001f:callvirt instance class [mscorlib]System.Text.StringBuilder [Mscorlib]system.text.stringbuilder::append ( char) il_0024:pop il_0025:nop il_0026:ldloc.0 il_0027:ldc.i4.1 IL_0028:add.ovf il_0029:stloc.0 il_002a: ldloc.0 Il_002b:ldloc.2 il_002c:ble.s il_001c il_002e:ldloc.1 il_002f:ldarg.1 Il_0030:callvirt instance class [Mscorlib]syste M.text.stringbuilder [Mscorlib]system.text.stringbuilder::append (String) il_0035:pop il_0036:ldarg.0 IL_0037:LDFL D class [Mscorlib]system.io.textwriter Netsdksamples.indentedwriter::mytextwriter il_003c:ldloc.1 IL_003D:CALLV IRT instance string [Mscorlib]system.text.stringbuilder::tostring () Il_0042:callvirt instance void [Mscorlib]system . Io. Textwriter::writeline (String) Il_0047:nop Il_0048:nop Il_0049:nop Il_004a:ret}//End of method Indentedwrite R::writeline
List B:
. method public Hidebysig instance void WriteLine (String message) cil managed {//Code size (0x42). maxstack 2. Locals ([0] class [mscorlib]System.Text.StringBuilder SB, [1] int32 i) il_0000:ldarg.0 il_0001:ldfld BOOL Indentedwriter::myprintflag IL_0006:BRFALSE.S il_0041 il_0008:newobj instance void [Mscorlib]system.te Xt. Stringbuilder::.ctor () il_000d:stloc.0 il_000e:ldc.i4.0 il_000f:stloc.1 il_0010:br.s IL_001f IL_0012: ldloc.0 IL_0013:LDC.I4.S Il_0015:callvirt Instance class [mscorlib]System.Text.StringBuilder [Mscorlib]system] . Text.stringbuilder::append (char) il_001a:pop il_001b:ldloc.1 il_001c:ldc.i4.1 il_001d:add il_001e:stloc.1 Il_001f:ldloc.1 il_0020:ldarg.0 il_0021:ldfld int32 indentedwriter::myindent il_0026:blt.s IL_0012 I l_0028:ldloc.0 Il_0029:ldarg.1 Il_002a:callvirt Instance class [mscorlib]System.Text.StringBuilder [Mscorlib]Sys] Tem. Text.stringbuildEr::append (String) il_002f:pop il_0030:ldarg.0 il_0031:ldfld class [Mscorlib]system.io.textwriter IndentedWr Iter::mytextwriter il_0036:ldloc.0 Il_0037:callvirt instance string [Mscorlib]system.text.stringbuilder::tostring ( ) Il_003c:callvirt instance void [Mscorlib]system.io.textwriter::writeline (String) Il_0041:ret}//End of method Indentedwriter::writeline
After compiling the code, I simply compared the following, more than 12 experiments found that the C # version of FindType.exe use reflection to list the methods belonging to a particular object, a narrow victory over the vb.net version. The latter is also slower than the slowest time of the former. What the hell is going on here? I am not an expert on IL, and I have very few current records. However, from the IL Code, the final IL code is very different, although the two pieces of code are functionally identical and perform the same tasks in the same order. This seems to be clearly visible. Is there anyone who would like to answer the following? I like it
Original link: http://www.techrepublic.com/article/vbnet-vs-c-round-2-pounding-on-performance/
VB.net vs. C #, round 2:pounding on Performance--vb.net vs C #, second wave: efficiency collisions