e*****r 发帖数: 379 | 1 Anybody can tell why vb.net codes for looping is faster than Csharp? |
s********o 发帖数: 861 | 2 How do you know that vb.net is faster than C# for looping? |
v******n 发帖数: 421 | 3 it's possible that VB compiler does more optimization than C# compiler
【在 e*****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Anybody can tell why vb.net codes for looping is faster than Csharp?
|
a****l 发帖数: 8211 | 4 it's much more possible that LZ just mistakenly thought vb is faster. VB,
especially after VB6, is based on .net framework, so its code is not much
different from C# code.
【在 v******n 的大作中提到】![](/moin_static193/solenoid/img/up.png) : it's possible that VB compiler does more optimization than C# compiler
|
e*****r 发帖数: 379 | 5 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.IO;
namespace My_Speed_Test
{
class Program
{
static void Main(string[] args)
{
DateTime tic = DateTime.Now;
UInt32 d=200;
double dd = 200;
int s = 0;
for (int a=1;a<=10000;a++)
{
for (int b=1;b<=10000;b++)
{
for (int c=1;c<=10;c++) |
e*****r 发帖数: 379 | 6 Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim a, b, c, s As Integer
s = 0
Dim d As Integer
d = 250
Dim dd As Double
dd = 250
Dim tic, toc As String
tic = (Now().Millisecond) / 1000 + Now().Second + (Now().Minute) *
60
For a = 1 To 10000
For b = 1 To 10000
For c = 1 To 10
dd = dd * 5.1234567 |
e*****r 发帖数: 379 | 7 above are C# codes and vb.net codes respectively(both compiled by vs.net 2008 Express):
In my laptop, results for speed testing:
Matlab:
ver 7.1: limit of array size overlimit for 1E4*1e4*1e1 size, has to
change to loop format 20x for loop
Total time: 38.01second
VB.net: total loop 1e9 (1 billion)
total time: 18.64 second
VSharp.net:
total time:21.5 second!!!
netSDK_CSC:
total time: 21.625 second!!!
Python 2.5:
10000x1000x10 loops with For-Loop (it's a very special one!) |
e*****r 发帖数: 379 | 8 It can't be interpreted simply by "overhead" costs (>3 second difference
between vb.net and C# codes), since there is no overhead (to my
understanding) between the two. CIL codes for both C# and VB.net should be
the same for both, aren't they?
I have been expecting vb.net "FOR loop" will be slower than that of C# due to
some overhead costs, but instead! no! |
c**t 发帖数: 2744 | 9 why not use exactly same init and format for both VB.NET and C#?
to
【在 e*****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : It can't be interpreted simply by "overhead" costs (>3 second difference : between vb.net and C# codes), since there is no overhead (to my : understanding) between the two. CIL codes for both C# and VB.net should be : the same for both, aren't they? : I have been expecting vb.net "FOR loop" will be slower than that of C# due to : some overhead costs, but instead! no!
|
g*****n 发帖数: 420 | 10 你反编译一下Assembly,看一下生成的IL指令不就知道原因了? |