性能比较 - C#,C ++,java [英] Performance comparison - C#, C++, java

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

问题描述

今天早上我读了这篇精彩的文章,它提出了一些有趣的

积分...例如,使用(写作

代码的TREMENDOUS性能优势) )而不是只是让垃圾收集做它'b
的事情。作者似乎是非常中立的,所以这不是C#比...更好的
。邮寄类型。事实上,他对C#非常残酷(它显然应该是b $ b b)应该分几个点。


Skeet,你应该喜欢这个。 :)

http:// click .wd-mag.email-publisher .... aa2d30b5V7MTb /

解决方案

"本文着眼于''威胁' C#/ Java已经变成了C ++ ......


威胁 (使用C#优于其他语言的好处)从来没有在开始时的表现(虽然他的基准测试对C#来说非常好)。


至于使用声明,他不明白如何正确处理对象

。如果一个对象有一个Dispose方法(并且很可能有一个

Finalizer)那么调用Dispose方法,周期非常重要。

using语句为我们做了这个。如果你不使用它,你需要打电话给

配置。这适用于具有Finalizer的对象,即使它没有

非托管资源。如果他没有理解他们,他就不应该对这些功能进行基准测试。后来他谈到了GC时间(显然是

显示使用帮助)。好吧,如果你调用Dispose,那就是

SuppressFinalize,那么你收集的对象要快得多(因为他们得到了一个集合中收集的
而不需要2)。这当然有

性能问题,但前提是代码不正确。他的陈述

说它要求用户非常了解事情并不是真的。只需在类上调用Dispose(或Close)即可。不知道是什么

重要的是什么。


总的来说,我觉得C#正在踢屁股(考虑到他的屁股) />
比较C#的第一个版本。


-mike

MVP


" ;丹尼尔比林斯利 <分贝********** @ NO.durcon.SPAAMM.com>在消息中写道

新闻:Oz ************** @ TK2MSFTNGP09.phx.gbl ...

我读过这篇精彩的文章今天早上,它提出了一些有趣的分数...比如,例如,
使用using()编写代码的TREMENDOUS性能优势,而不是让垃圾收集执行
it'的事。作者看起来很中立,所以这不是C#比java更好。邮寄类型。事实上,他在几个方面对C#(显然应该是
)非常残酷。

Skeet,你应该喜欢这个。 :)

http:// click .wd-mag.email-publisher .... aa2d30b5V7MTb /



" Michael Giagnocavo [MVP]" <毫克******* @ Atrevido.net>写在消息

新闻:eT ************** @ TK2MSFTNGP09.phx.gbl ...

"本文看起来在''威胁''C#/ Java已成为C ++ ......

威胁 (使用C#优于其他语言的好处)从来没有在性能上开始(虽然他的基准测试看起来非常适合
C#)。


不,但是威胁可以通过C#中令人沮丧的性能弱点来缓解。这肯定是VB6的瘟疫之一 - 没有严重

程序员会认为它是一个真实的应用程序,对吗?

就using语句而言,他并不理解如何正确处理
对象。如果一个对象有一个Dispose方法(并且很可能有一个
Finalizer),那么调用Dispose方法,周期非常重要。
using语句为我们做了。如果您不使用它,您需要致电
Dispose。这适用于具有Finalizer的对象,即使它没有非托管资源。如果他不理解这些特征,他就不应该对这些特征进行基准测试。后来他谈到了GC时间(显然是显示使用帮助)。好吧,如果你调用Dispose并且那就是
SuppressFinalize,那么你可以更快地收集对象(因为他们将
收集在一个集合中而不是需要2)。这当然有性能问题,但前提是代码不正确。他声明要求用户很好地理解事物的陈述并不是真的。只需在类上调用Dispose(或Close)即可。不要看
重要的是什么。


我认为他非常清楚地知道你是否可以调用Dispose

在他看来是最重要的。


你确实采取了与我不同的观点。我会说我去过许多研讨会,MSDN咖啡馆,VSLive等等,而且从来没有听过一个单独的b
发言人,微软的员工或者说,在每个班级上调用Dispose

你可以非常重要。事实上,我所听到的和b $ b over之类的东西是忘掉它。因为GC会注意你的背部。是的,

每个人都在资源上近距离关闭(在try / finally块中)

就像文件或数据库连接一样,但这是另一回事,不是吗?


现在已经批准了,我对于

Dispose()和Finalize()以及GC的技术细节相当无知 - 但我认为这才是重点。有人像我这样的
已被引导相信我不必担心太多因为GC

是如此美好的事情,而且不一定是案件。我说不一定是

,因为我们当然在谈论某种类型的

应用程序,它甚至对重要的事情都很重要。也就是说,很多商家根本没有必要考虑尽可能快地创建数百万美元的b $ b对象。

总的来说,我感觉C#正在踢屁股(考虑到他比较C#的第一个版本)。




确实。


BTW,什么样的人在业余时间写D语言? :)


我还认为像字符串连接结果这样的东西非常有趣。我认为C#开发人员的一般态度倾向于使用stringbuilder而不是连续的连接,例如,

,但是测试结果表明性能打击不是'''真的很糟糕。


这是我直接从

文档中谈论的一个例子:


自动内存管理是在托管执行期间运行时提供的通用语言的一种服务。公共语言运行库的

垃圾收集器管理

应用程序的内存分配和释放。对于开发人员来说,这意味着您在开发托管应用程序时不必编写代码来执行内存管理任务。

自动内存管理可以消除常见问题,例如

忘记释放一个对象并导致内存泄漏,或者试图为已经被释放的对象访问
访问内存。

I read this fantastic article this morning, which raises some interesting
points... like, for example, the TREMENDOUS performance advantage of writing
code with using() as opposed to just letting the garbage collection do it''s
thing. The author appears to be quite neutral, so this is not a "C# is
better than java" type of post. In fact, he is pretty brutal to C# (that it
apparently deserves) on several points.

Skeet, you ought to love this one. :)

http://click.wd-mag.email-publisher....aa2d30b5V7MTb/

解决方案

"This article looks at the ''threat'' C#/Java has become to C++..."

The "threat" (benefit in using C# over other language) was never in
performance to begin with (although his benchmarks seem pretty good for C#).

As far as the using statement, he didn''t understand how to Dispose an object
correctly. If an object has a Dispose method (and most likely has a
Finalizer) then it''s VERY important to call the Dispose method, period. The
using statement does that for us. If you don''t use it, you need to call
Dispose. This applies to object with a Finalizer, even if it has no
unmanaged resources. He shouldn''t be benchmarking these features if he
doesn''t understand them. Later he talks about the GC time (apparently
showing that using helps). Well, if you call Dispose and that does the
SuppressFinalize, then you get objects collected much faster (since they get
collected in one collection instead of needing 2). This of course has
performance issues, but only if you code incorrectly. His statements of
saying that it requires the users to understand things very well is not
true. Just calling Dispose (or Close) on a class is enough. Don''t see what
the big deal is.

Overall, I get the feeling that C# is kicking butt (considering he''s
comparing the first release of C#).

-mike
MVP

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...

I read this fantastic article this morning, which raises some interesting
points... like, for example, the TREMENDOUS performance advantage of writing code with using() as opposed to just letting the garbage collection do it''s thing. The author appears to be quite neutral, so this is not a "C# is
better than java" type of post. In fact, he is pretty brutal to C# (that it apparently deserves) on several points.

Skeet, you ought to love this one. :)

http://click.wd-mag.email-publisher....aa2d30b5V7MTb/



"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...

"This article looks at the ''threat'' C#/Java has become to C++..."

The "threat" (benefit in using C# over other language) was never in
performance to begin with (although his benchmarks seem pretty good for C#).

No, but the "threat" would be mitigated by a percieved performance weakness
in C#. That certainly was one of the plagues of VB6 - no "serious"
programmer would consider it for a "real" application, right?

As far as the using statement, he didn''t understand how to Dispose an object correctly. If an object has a Dispose method (and most likely has a
Finalizer) then it''s VERY important to call the Dispose method, period. The using statement does that for us. If you don''t use it, you need to call
Dispose. This applies to object with a Finalizer, even if it has no
unmanaged resources. He shouldn''t be benchmarking these features if he
doesn''t understand them. Later he talks about the GC time (apparently
showing that using helps). Well, if you call Dispose and that does the
SuppressFinalize, then you get objects collected much faster (since they get collected in one collection instead of needing 2). This of course has
performance issues, but only if you code incorrectly. His statements of
saying that it requires the users to understand things very well is not
true. Just calling Dispose (or Close) on a class is enough. Don''t see what the big deal is.
I think he makes it quite clear that having to know if you CAN call Dispose
is the big deal in his opinion.

You sure took this point differently than I did. I''ll say that I''ve been to
many many seminars, MSDN cafes, VSLive!, etc. and have never heard a single
speaker, Microsoft employee or otherwise, say calling Dispose on every class
you can is "VERY important". In fact, what I''ve heard preached over and
over is "forget about it" because the GC will watch your back. Yes,
everyone preaches close close close (in try/finally blocks) on resources
like file or database connections but that''s a different thing, isn''t it?

Now granted, I''m fairly ignorant in regards to the technical details of
Dispose() and Finalize() and GC - but I think that''s the point. Someone
like me has been led to believe I don''t have to worry about much because GC
is such a beautiful thing, and that''s not necessarily the case. I say not
necessarily, because of course we''re talking about a certain type of
application where it would even matter to a significant. That is, many
business simply don''t have to consider a scenario of creating millions of
objects as fast as they can.

Overall, I get the feeling that C# is kicking butt (considering he''s
comparing the first release of C#).



Indeed.

BTW, what kind of guy writes a language like D in his spare time? :)

I also thought things like the string concatenation results were very
interesting. I think the general attitude of C# developers tends to be anal
about using stringbuilder instead of successive concatenations, for example,
but the test results show the performance hit isn''t really that bad.


Here''s an example of what I was talking about straight from the
documentation:

"Automatic memory management is one of the services that the common language
runtime provides during Managed Execution. The common language runtime''s
garbage collector manages the allocation and release of memory for an
application. For developers, this means that you do not have to write code
to perform memory management tasks when you develop managed applications.
Automatic memory management can eliminate common problems, such as
forgetting to free an object and causing a memory leak, or attempting to
access memory for an object that has already been freed."


这篇关于性能比较 - C#,C ++,java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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