它有更好的表现?静态与对象 [英] which has better performance? static versus objects

查看:133
本文介绍了它有更好的表现?静态与对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设计了一个C#控制台应用程序合并,并使用面向对象的设计分割大文件(大约大小4GB)。它涉及到读/写XML,平面文件和图像。我对读者和作家班。



在合并了大约零点12分,而分裂了超过四点30小时。然后,我已经加强了分裂的性能由输出文件分发到subdirectorys而不是用单一的目录,达到零时五十分。



我的老板问我一切转换成静态的过程式编程,而不是对象。他合并比较00:50的分割不均衡说00:12。他希望通过转换成静态有在0点30分进行的分裂



现在我知道静态调用是更快的根据的这个。但我不同意所有静态会更好,因为我将不得不使用参考,并在方法出参数



我的问题是:




  1. 是什么原因分割文件到子目录比使用单个输出目录多快? (即为文件数量巨大> 200,000)

  2. 难道还有比从对象转换我的代码,以静态,以实现更高的性能更好的办法?


解决方案

您是否了解您的计划?



您应该配置您的码。对象是速度快,unoptimal代码是死的慢。



在你优化它,这个任务将是I / O的约束呢(这意味着它花费大量的时间等待磁盘来获取数据的另一部分)。



和是的,你的老板是更好做霸道之类的东西打高尔夫球或dilberting左右,不会告诉你胡说有关软件设计。
',因为你不是想打高尔夫对他来说,你呢?


I have designed a C# console application to merge and split huge files (about 4GB of size) using OOP design. It involves reading/writing xml, flat-files, and images. I have classes for readers and writers.

The merging took about 00:12, while the splitting took more than 04:30 hours. Then I've enhanced the performance of the splitting to reach 00:50 by distributing the output files into subdirectorys rather than using single directory.

My boss's asking me to convert everything into static procedural programming, but not objects. He says 00:12 for merging comparing to 00:50 for splitting is not balanced. He wants to have the splitting done in 00:30 minutes by converting into static.

Now i know static calls are faster according to this. However I disagree that all static will be better since i will have to use "ref" and "out" parameters in methods.

My questions are:

  1. What is the reason for splitting files into subdirectory is much more faster than using a single output directory? (i.e. for huge number of files >200,000)
  2. Is there a better way than converting my code from object to static, in order to achieve higher performance?

解决方案

Did you profile your program?

You should profile your code. Objects are fast, unoptimal code is dead slow.

After you optimize it, this task would be I/O bound anyway (which means it spends most of time waiting for disks to fetch another part of data).

And yeah, your boss is better off doing bossy things like playing golf or dilberting around, not telling you bullshit about software design. 'cause you're not trying to play golf for him, do you?

这篇关于它有更好的表现?静态与对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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