Collection Performance: Converting A List To Different Collection Types – dotNet...
source link: https://dotnettips.wordpress.com/2021/10/21/collection-performance-converting-a-list-to-different-types/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Collection Performance: Converting A List To Different Collection Types
What if you already have a collection in memory, like after calling a service or database, and you need to return it as a different collection type?
public Person[] GetPeopleAsArray()
{
return people.ToArray();
}
public LinkedList<Person> GetPeopleAsLinkedList()
{
return new LinkedList<Person>(people);
}
In the example above, the people variable is typed as List<Person>(), which you can see for yourself in the code I used to run the benchmarks, that is available online.
Benchmark Results
Below are the benchmark results for various ways to return a collection from a List<>. These results are for your own information. As I have said already, remember to perform benchmarking on your own types.
© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
I live in San Diego, Ca USA View all posts by dotNetDave
Recommend
-
68
An convenience method for converting to and from different casing types. · GitHub Instantly share code, notes, and snippets. ...
-
4
February 25, 2015 Converting a Tree to a List in JavaScript With the meteoric rise of JavaScript MVC frameworks, data structures and algo...
-
5
Measuring Performance of Different JavaScript Loop TypesOptimize your JavaScript code by using the right loop types.
-
15
Google CloudEvents for .NET Overview This repository contains .NET libraries for CloudEvents issued by Google. The Google.Events package is very small and has no dependencies. Its purpose is to expose at...
-
5
Effective form to compare different types of object list advertisements public class State{ String code; int occurValue; int name; }...
-
2
Collection Performance: Looping Over Other Collection Types Subscribe to get access Read more of this content about code performance for collections under simulated load when you subscribe...
-
4
Collection Performance: Looping Over Collection – Array vs. List Most of the benchmarks these articles tests a collection is doing so using List<> that uses a real-world business object (Person). I was curious...
-
0
Reading Time: 4 minutes Rust’s standard library includes a number of very useful data structures called collections. A collection is something that holds zero or more elements in some fashion that a...
-
0
Converting Replica Set to Standalone Back to the Blog
-
2
TLDR; this article covers how to convert between strings and numbers There's different data types and a need to convert between them. For example, we often need to convert between text and numbers for presen...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK