需要优化......汇编代码是否可用? [英] Optimization needed... Is Assembly code available?

查看:55
本文介绍了需要优化......汇编代码是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要优化闭环。通常我会使用汇编,但我不知道b $ b事件是否可用于VB.NET。我会解释一下这个案子,也许一些

你可以告诉我。


我有一个byte()(字节数组)包含大约100,000个元素(少一点,

但总是大约80,000-95,000)。我需要把它的数据作为

int16并将int16与参考值比较


现在,我正在使用从中创建的MemoryStream byte(),一个BinaryReader

从MemoryStream(ReadInt16)读取,然后将int16与

参考值进行比较,如果int16大于参考

值。如果所有值都低于参考值,则

函数返回true。如果它在第一个循环之后返回,那么它没关系,

但是如果它贯穿所有元素那么它太长了。在汇编它

将花费更少的时间,因为我可以在CPU的一个寄存器中移动参考值

并将其保留在那里我的循环运行并且

直接在byte()中迭代以一次获得2个字节。


在VB.NET中它是一个功能在大约10行代码中(甚至可能比b
更低),但它需要高达50%的CPU(当在任务管理器中查看时)

这也是一种方式很多,因为它经常运行。当它没有运行时(许多

其他东西在应用程序中运行),该应用占用了大约1%-2%的CPU,

当这个关闭循环开始时被叫,该应用程序得到了* b $ b CPU的30%-50%...由于该功能被调用,它有点过分

每秒约8-10次。


感谢您的帮助


ThunderMusic

Hi,
I need to optimize a close loop. Usually I would use assembly, but I don''t
event know if it''s available to VB.NET. I''ll explain the case and maybe some
of you will be able to advise me.

I have a byte() (byte array) containing about 100,000 elements (a bit less,
but always is around 80,000-95,000). I need to take the data from it as
int16 and compare the int16 to a reference value

for now, I''m using a MemoryStream created from the byte(), a BinaryReader
that reads from the MemoryStream (ReadInt16) and then compare the int16 to a
reference value and return false if the int16 is greater than the reference
value. if all the values are lower than the reference value, then the
function returns true. If it returns after the first loop or so, it''s ok,
but if it runs through all the elements it''s way too long. In assembly it
would take way less time than that, because I could move the reference value
in one of the CPU''s register and leave it there as long as my loop runs and
iterate directly in the byte() to get 2 bytes at a time.

In VB.NET it''s a function that stands in about 10 lines of code (maybe even
lower), but it takes up to 50% of the CPU (when looked in the task manager)
which is way too much because it runs very often. When it does not run (many
other things are running in the app), the app takes about 1%-2% of the CPU,
when this close loop starts being called, the app get''s to 30%-50% of the
CPU... it''s a bit excessive due to the fact that the function is called
about 8-10 times a second.

thanks for your help

ThunderMusic

推荐答案



仅供参考,有一个致力于解决性能问题的小组;

microsoft.public.dotnet.framework.performance
我需要优化一个闭环。通常我会使用汇编,但我不知道它是否可用于VB.NET。
I need to optimize a close loop. Usually I would use assembly, but I don''t
event know if it''s available to VB.NET.




它不是,但你可以编写汇编代码,编译成一个DLL

,如果你愿意,可以从VB.NET调用它。


您也可以尝试使用指针在C#(不安全代码)或C ++中走路

数组。


无论如何我不会太担心CPU利用率,更多

关于在循环中花费的时间。使用探查器!

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



It isn''t, but you can certainly write assembly code, compile to a DLL
and call that from VB.NET if you want.

You could also try using pointers in C# (unsafe code) or C++ to walk
the array.

In any case I wouldn''t worry too much about the CPU utilization, more
about the time spent in the loop. Use a profiler!
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.




" Mattias Sj?gren" <毫安******************** @ mvps.org>在消息中写道

news:u%**************** @ tk2msftngp13.phx.gbl ...

"Mattias Sj?gren" <ma********************@mvps.org> wrote in message
news:u%****************@tk2msftngp13.phx.gbl...

仅供参考,有一个致力于解决性能问题的小组;
microsoft.public.dotnet.framework.performance

FYI, there''s a group dedicated to performance issues;
microsoft.public.dotnet.framework.performance




非常感谢,我没有'不知道,因为这是我第一次有一个真正的

性能问题,所以我会使用一个分析器(如建议的那样)并尝试发布

那里。非常感谢。


ThunderMusic



thanks a lot, I didn''t know because it''s the first time I have a real
performance issue, so I''ll use a profiler (as advised) and try posting
there. Thanks a lot.

ThunderMusic


ThunderMusic写道:
ThunderMusic wrote:
我需要优化一个闭环。通常我会使用汇编,但我不知道它是否可用于VB.NET。我会解释一下这个案子
也许你们中的一些人可以给我建议。
I need to optimize a close loop. Usually I would use assembly, but I
don''t event know if it''s available to VB.NET. I''ll explain the case
and maybe some of you will be able to advise me.




要回答你的原始问题,通常不可能用.NET语言编写
内联汇编,因为.NET程序集旨在在平台之间移植。但是,有一些技术可以让你的b
包含内联CLR字节码,当你需要优化热点或需要访问CLR功能时,这是很方便的。你的语言

不允许访问。这里有一个工具,由Mike写的

Stall,它实现了这个:

http://blogs.msdn.com/jmstall/archiv...21/377806.aspx


-

Derrick Coetzee,MCAD,MSFT(语音服务器)

此帖子按原样提供。没有保证,也没有赋予

权利。



To answer your original question, it is not normally possible to write
inline assembly in a .NET language, because .NET assemblies are intended to
be portable between platforms. However, there are techniques by which you
can include inline CLR bytecode, which is handy when either you need to
optimize a hotspot or you need access to a CLR feature that your language
does not give access to. There is a tool available here, written by Mike
Stall, that enables this:

http://blogs.msdn.com/jmstall/archiv...21/377806.aspx

--
Derrick Coetzee, MCAD, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.


这篇关于需要优化......汇编代码是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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