如何加快小数和双倍的ToString? [英] How can I speed up ToString of decimal and double?

查看:56
本文介绍了如何加快小数和双倍的ToString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们的应用程序中有一部分涉及数百万条记录,并对它们进行了一些处理。我们已经取得了相当不错的性能提升

开发自定义DateTime.ToString和自定义int.ToString,但是我们

找不到任何线索做十进制和双精度,如果将它们放在一起(十进制和双精度),这将是

负载的一半。通过更改我们的

DateTime和Int ToStrings,我们实现了84%的性能提升,所以现在我们想要优化十进制和双倍的
。任何人都会有一个链接或线索

我们应该怎么做?实际上我们通过强制我们的格式而不是依靠文化和格式字符串和其他来加快它...我们发现这个页面

我们的DateTime(
http://geekswithblogs.net/akraus1/ar。 ../23/76146.aspx ),所以如果你给
有类似的双倍和小数,那将非常感激。


谢谢


ThunderMusic


PS我知道这与100%的性能有关,但我觉得来自

框架和一般论坛的人也会关注,对于c#,它是

只是因为我们的事情都是用c#完成的,我很感激在c#中有b / b $ b的例子......如果可能......;)

解决方案

第一个问题:

为什么首先需要将它们转换为字符串?


Peter

-

网站: http://www.eggheadcafe.com

UnBlog: http://petesbloggerama.blogspot.com

短网址&更多: http://ittyurl.net


ThunderMusic写道:




我们的应用程序的一部分涉及数百万条记录并且做了

对它们进行一些处理。我们已经取得了相当不错的性能提升

开发自定义DateTime.ToString和自定义int.ToString,但是我们

找不到任何线索做十进制和双精度,如果将它们放在一起(十进制和双精度),这将是

负载的一半。通过更改我们的

DateTime和Int ToStrings,我们实现了84%的性能提升,所以现在我们想要优化十进制和双倍的
。任何人都会有一个链接或线索

我们应该怎么做?实际上我们通过强制我们的格式而不是依靠文化和格式字符串和其他来加快它...我们发现这个页面

我们的DateTime(
http://geekswithblogs.net/akraus1/ar。 ../23/76146.aspx ),所以如果你给
有类似的双倍和小数,那将非常感激。


谢谢


ThunderMusic


PS我知道这与100%的性能有关,但我觉得来自

框架和一般论坛的人也会关注,对于c#,它是

只是因为我们的事情都是用c#完成的,我很乐意在c#中使用

示例,如果可能的话......;)


< blockquote> 2007年3月28日星期三19:58:42 -0400,ThunderMusic

< No ******************* ******@NoSpAm.comwrote:


>
我们的应用程序的一部分涉及数百万条记录并且做了
对它们进行一些处理。通过开发自定义DateTime.ToString和自定义int.ToString,我们已经取得了相当不错的性能提升,但是我们无法找到关于做十进制和双精度的任何线索,这会如果将它们放在一起(十进制和双倍),那么它们的负载是一半。通过更改我们的DateTime和Int ToStrings,我们实现了84%的性能提升,所以现在我们想要优化十进制和双倍。任何人都会有关于我们应该如何做的链接或线索?实际上我们通过强制我们的格式加速它而不是依赖于文化和格式字符串和其他...我们找到了这个页面
我们的DateTime(
http://geekswithblogs.net/akraus1/ar.../23/76146.aspx ),所以如果你有类似的双倍和十进制的东西,我将非常感激。

谢谢

ThunderMusic

PS我知道它与100%的性能有关,但我觉得来自
框架和一般论坛的人也会关注,对于c#,它只是因为我们的事情已经完成了c#我希望在c#中有
示例,如果可能的话......;)



你想要什么格式的double或decimal:12.3456或1.23456 e + 001?


任何格式都可以通过整数和其他

字符的组合来限制,因此您可能拥有所需的全部内容。


rossum


因为我们正在将它们写入CSV文件,所以我们必须将它们转换为

字符串。即使我们不使用ToString并使用例如
StreamWriter.WriteInt()或类似的东西,它似乎在

中执行ToString背景,因为它跟ToString一样慢,然后写了

...


谢谢


ThunderMusic


" Peter Bromberg [C#MVP]" < pb ******* @ yahoo.yabbadabbadoo.com写在

消息新闻:6C ********************* ************* @ microsof t.com ...


第一个问题:

为什么你需要首先将它们转换成字符串吗?


彼得

-

网站: http://www.eggheadcafe.com

UnBlog: http://petesbloggerama.blogspot.com

短网址&更多: http://ittyurl.net


ThunderMusic写道:


>
我们的应用程序的一部分涉及数百万条记录,并且
做了一些处理它们。通过开发自定义DateTime.ToString和自定义int.ToString,我们已经取得了相当不错的性能提升,但是我们无法找到关于做十进制和双精度的任何线索,这会如果将它们放在一起(十进制和双倍),那么它们的负载是一半。通过更改我们的DateTime和Int ToStrings,我们实现了84%的性能提升,所以现在我们想要优化十进制和双倍。任何人都会有一个链接或线索
我们应该怎么做?实际上我们通过强制我们的格式来加速它,而不是依赖于文化和格式字符串和其他...我们发现这个
页面
我们的DateTime(
http://geekswithblogs.net/akraus1/ar ... / 23 /76146.aspx ),所以如果
你有类似的双倍和小数,那将非常感激。

谢谢
ThunderMusic

PS我知道它与100%的性能有关,但我觉得来自
框架和一般论坛的人也会关注,对于c#,它只是因为我们的事情已经完成了c#我希望在c#中有可能的例子......;)



Hi,
We have a part of our application that deals with millions of records and do
some processing of them. We''ve achieved a pretty good performance gain by
developping a custom DateTime.ToString and a custom int.ToString, but we
can''t find any clue on doing for decimal and double, which would be about
half the load if they are put together (decimal and double). By changing our
DateTime and Int ToStrings, we achieved a 84% performance gain, so now we
want to optimize decimal and double. Anyone would have a link or a clue on
how we should do it? Actually we speed it up by forcing our format rather
than relying on cultures and format string and others... we found this page
for our DateTime (
http://geekswithblogs.net/akraus1/ar.../23/76146.aspx ), so if you
have something similar for double and decimal it would be very appreciated.

Thanks

ThunderMusic

P.S. I know it''s 100% performance related, but I feel people from the
framework and general forums could be concerned too, and for the c#, it''s
just because our things are done with c# and I would appreciate to have
examples in c# if possible... ;)

解决方案

First question:
Why do you need to convert them to strings in the first place?

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ThunderMusic" wrote:

Hi,
We have a part of our application that deals with millions of records and do
some processing of them. We''ve achieved a pretty good performance gain by
developping a custom DateTime.ToString and a custom int.ToString, but we
can''t find any clue on doing for decimal and double, which would be about
half the load if they are put together (decimal and double). By changing our
DateTime and Int ToStrings, we achieved a 84% performance gain, so now we
want to optimize decimal and double. Anyone would have a link or a clue on
how we should do it? Actually we speed it up by forcing our format rather
than relying on cultures and format string and others... we found this page
for our DateTime (
http://geekswithblogs.net/akraus1/ar.../23/76146.aspx ), so if you
have something similar for double and decimal it would be very appreciated.

Thanks

ThunderMusic

P.S. I know it''s 100% performance related, but I feel people from the
framework and general forums could be concerned too, and for the c#, it''s
just because our things are done with c# and I would appreciate to have
examples in c# if possible... ;)


On Wed, 28 Mar 2007 19:58:42 -0400, "ThunderMusic"
<No*************************@NoSpAm.comwrote:

>Hi,
We have a part of our application that deals with millions of records and do
some processing of them. We''ve achieved a pretty good performance gain by
developping a custom DateTime.ToString and a custom int.ToString, but we
can''t find any clue on doing for decimal and double, which would be about
half the load if they are put together (decimal and double). By changing our
DateTime and Int ToStrings, we achieved a 84% performance gain, so now we
want to optimize decimal and double. Anyone would have a link or a clue on
how we should do it? Actually we speed it up by forcing our format rather
than relying on cultures and format string and others... we found this page
for our DateTime (
http://geekswithblogs.net/akraus1/ar.../23/76146.aspx ), so if you
have something similar for double and decimal it would be very appreciated.

Thanks

ThunderMusic

P.S. I know it''s 100% performance related, but I feel people from the
framework and general forums could be concerned too, and for the c#, it''s
just because our things are done with c# and I would appreciate to have
examples in c# if possible... ;)

What format of double or decimal do you want: 12.3456 or 1.23456e+001?

Any format can be constricted from a combination of integers and other
characters, so you may well have all that you need to hand.

rossum


because we are writing them to a CSV File, so we must convert them to
string. And even if we don''t use ToString and use for example
StreamWriter.WriteInt() or something like this, it seems to do a ToString in
the background because it''s as slow as doing a ToString and a Write
afterward...

Thanks

ThunderMusic

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:6C**********************************@microsof t.com...

First question:
Why do you need to convert them to strings in the first place?

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ThunderMusic" wrote:

>Hi,
We have a part of our application that deals with millions of records and
do
some processing of them. We''ve achieved a pretty good performance gain by
developping a custom DateTime.ToString and a custom int.ToString, but we
can''t find any clue on doing for decimal and double, which would be about
half the load if they are put together (decimal and double). By changing
our
DateTime and Int ToStrings, we achieved a 84% performance gain, so now we
want to optimize decimal and double. Anyone would have a link or a clue
on
how we should do it? Actually we speed it up by forcing our format rather
than relying on cultures and format string and others... we found this
page
for our DateTime (
http://geekswithblogs.net/akraus1/ar.../23/76146.aspx ), so if
you
have something similar for double and decimal it would be very
appreciated.

Thanks

ThunderMusic

P.S. I know it''s 100% performance related, but I feel people from the
framework and general forums could be concerned too, and for the c#, it''s
just because our things are done with c# and I would appreciate to have
examples in c# if possible... ;)



这篇关于如何加快小数和双倍的ToString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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