C#十进制数据类型的表现 [英] C# Decimal datatype performance

查看:112
本文介绍了C#十进制数据类型的表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在C#中的财务应用中的性能(即速度)是至关重要的。因为它是一个理财软件我必须集中使用十进制数据类型。

I'm writing a financial application in C# where performance (i.e. speed) is critical. Because it's a financial app I have to use the Decimal datatype intensively.

我已经优化了code,就像我可以用一个分析器的帮助。使用十进制之前,一切都与双数据类型完成的,速度是快好几倍。然而,双并不是因为其二进制性质的选择,引起了很多precision错误在多个操作过程。

I've optimized the code as much as I could with the help of a profiler. Before using Decimal, everything was done with the Double datatype and the speed was several times faster. However, Double is not an option because of its binary nature, causing a lot of precision errors over the course of multiple operations.

有没有办法,我可以用C#接口,可以给我在.NET中的原生数据类型小数?

Is there any decimal library that I can interface with C# that could give me a performance improvement over the native Decimal datatype in .NET?

,我发现我不太清楚,所以这里有一些额外的细节:

Based on the answers I already got, I noticed I was not clear enough, so here are some additional details:


  • 应用必须尽可能快,因为它可以去可能(即尽可能快地使用双时代替小数将是一个梦想)。双约15倍不是十进制快,因为操作是基于硬件的。

  • 的硬件已顶尖的(我在双氙气四核运行),应用程序使用线程,因此CPU占用率始终在机器上100%。此外,该应用程序是在64位模式,这使得它比32bit的一个定量的性能优势正在运行。

  • 我过去的​​优化理智点(超过一个半月优化;无论你相信与否,现在大约需要的什么了做我最初用作参考相同的计算1/5000。 );这种优化所涉及的一切:字符串处理,I / O,数据库访问和索引,存储,循环,改变一些事情作了方式,甚至用开关而不是如果无处不在这就不一样了。探查现在清楚地显示出剩余性能的罪魁祸首是十进制数据类型的运营商。没有别的是加入了相当多的时间。

  • 您要相信我在这里:据我已经走了,因为我可以有可能在C#.NET的境界去优化应用程序,我在其目前的表现感到惊讶。我现在为了提高十进制性能,一些接近双找一个好主意。我知道这只是一个梦想,但只是想检查我以为一切可能的。 :)

谢谢!

推荐答案

您可以使用长数据类型。当然,你将不能够存储分数在那里,但是如果你code你的应用程序存储便士,而不是英镑,你会没事的。精度是长期的数据类型100%,除非你与广大的工作(使用64位的长型),你会没事的。

you can use the long datatype. Sure, you won't be able to store fractions in there, but if you code your app to store pennies instead of pounds, you'll be ok. Accuracy is 100% for long datatypes, and unless you're working with vast numbers (use a 64-bit long type) you'll be ok.

如果您不能强制存储便士,然后包装在一个类整数并使用它。

If you can't mandate storing pennies, then wrap an integer in a class and use that.

这篇关于C#十进制数据类型的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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