简体   繁体   English

Boo / C#:返回收集性能

[英]Boo/C#: Returning a collection performance

I have a function that gets a collection by reference, iterates over it, constructs a new collection of the same length containing updated structs, returns that collection (or rather a reference to it, since it's Boo/C# code). 我有一个函数,该函数通过引用获取集合,对其进行迭代,构造一个包含更新结构的相同长度的新集合,返回该集合(或更确切地说是对它的引用,因为它是Boo / C#代码)。

I'm worried about performance of such a function. 我担心这种功能的性能。 Is performance a lot worse than just updating the collection by reference? 与仅通过引用更新集合相比,性能要差很多吗? I need to call this function tens of times per second. 我需要每秒调用数十次此函数。

Thank you. 谢谢。 Alisa. 阿利萨。

PS: Why am I doing this? PS:我为什么要这样做? I'm trying to move onto functional programming and make it as pure as possible. 我正在尝试进行函数式编程,并使其尽可能纯净。

It will be slower, but not by much. 会慢一些,但不会慢很多。 It will also consume more memory as you'll have two collections in RAM whenever you're updating the structs. 每当您更新结构时,它还将消耗更多内存,因为您将在RAM中拥有两个集合。

The impact on performance will also be affected by your collections' sizes. 对性能的影响也将受到集合大小的影响。

The best way to answer your question is to create both functions, then profile them. 回答问题的最好方法是创建两个函数,然后对其进行概要分析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM