VB-C +速度差 [英] VB - C+ Speed Differential

查看:95
本文介绍了VB-C +速度差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么?突然我可以发贴了吗?

使用C + DLL,我可以搜索目录0.46秒内可存储12000个块(512字节记录).真是动人.

我可以使用以下代码进行搜索:

导入 System.IO. DirectoryInfo

Imports System.IO.DirectoryInfo

导入 Microsoft.VisualBasic.FileIO

导入 System.Globalization

导入 System.Collections

公共 Form11

Public Class Form11

继承 System.Windows.Forms.表单

    Inherits System.Windows.Forms.Form

   sw 新建 秒表

        Dim sw As New Stopwatch

   t 字符串

        Dim t As String

私有 Sub BeingTimed()

    Private Sub BeingTimed()

   foo As System.Collections.ObjectModel. Of 字符串)

        Dim foo As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

   foo = 文件系统 .FindInFiles("G:\ BOOK \" 克里斯不再怀疑他们会这么做" False ,Microsoft.VisualBasic.FileIO. SearchOption .SearchAllSubDirectories)

        foo = FileSystem.FindInFiles("G:\BOOK\", "Chris no longer doubted that they would", False, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories)

   返回

        Return

结束

    End Sub

私有 Sub Button1_Click( ByVal 发件人 系统.对象 ByVal e As 系统. EventArgs ) 手柄 Button1.单击

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

   Stopwatch1()

        Stopwatch1()

   BeingTimed()

        BeingTimed()

   Stopwatch1(错误)

        Stopwatch1(False)

结束

    End Sub

私有 Sub Stopwatch1(可选 ByRef 重设目标 布尔值 = )

    Private Sub Stopwatch1(Optional ByRef Reset As Boolean = True)

   如果重设然后

        If Reset Then

      sw.Reset()

            sw.Reset()

      sw.Start()

            sw.Start()

   其他

        Else

      ts As TimeSpan = TimeSpan .FromMilliseconds(sw.ElapsedMilliseconds) '开始

            Dim ts As TimeSpan = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds) ' Start

      t = 字符串 .Format( CultureInfo .CurrentCulture, "{0:00}:{1:00}:{2:00}.{3:00}" ,小时,小时. ,ts.Seconds,ts.Milliseconds)

            t = String.Format(CultureInfo.CurrentCulture, "{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)

      ts = ts

            ts = ts

   结束 如果

        End If

结束

    End Sub

结束

End Class

 

我的问题是,那非常快.为什么C +和VB之间存在巨大的速度差异? 因为VB是托管代码",实际上并没有 回答问题.

My question is, that's pretty fast. Why the enormous speed differential between C+ and VB? "Becase VB is managed code", doesn't really answer the question.

 

Renee

推荐答案

蕾妮,

许多Framework代码可能已经过优化,并且可能是使用C编译器以非托管代码编写的.

A lot of the Framework code is probably optimised and probably written in unmanaged code using a C compiler.

我认为编写代码应尽可能接近机器语言".或尽可能接近汇编语言"

I believe writing code as close to "machine language" or as close to "assembly language"

尽可能使(几乎)产生最快的代码.

as possible results in ( almost ) the fastest code being produced.

 

如果Microsoft的编码人员可以用二进制的1和0进行编码,或者他们知道为执行特定任务而要编写的正确字节顺序,我敢打赌,他们会的!!大声笑!但是,他们可能使用C编译器或/以及一些汇编语言".

If the coders at Microsoft could code in the 1's and 0's of binary or they knew the correct sequence of bytes to write to perform a certain task, I bet they would!!  LOL!! However they probably use a C compiler or / and a bit of "assembly language".

 

我希望这会有所帮助.  :)

I hope this helps.  :)

.Net Framework代码有时令我感到惊讶,尤其是LINQ查询的速度.  :-)

The .Net Framework code suprises me at times, especially with the speed of LINQ queries.  :-)

C +或C ++(如果您正在谈论Visual C ++),则可能更近

C+ or C++ ( if you are talking of Visual C++ ) it is probably closer

也要比VB.Net到标准C,因此速度差异也很大.

to standard C than VB.Net too, hence the speed difference.

 


这篇关于VB-C +速度差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆