Appendix A. Performance Cheat Sheet

List<T>

Methods

Complexity (for n elements and count m)

Add

O(1)

AddRange

O(n + m)

AsReadOnly

O(1)

BinarySearch

O(log n)

Clear

O(n)

Contains

O(n)

ConvertAll

O(n)

CopyTo

O(n)

Exists

O(n)

Find

O(n)

FindAll

O(n)

FindIndex

O(n)

ForEach

O(n)

GetRange

O(n)

IndexOf

O(n)

Insert

O(n)

InsertRange

O(n + m)

LastIndexOf

O(n)

RemoveAll

O(n)

RemoveAt

O(n)

RemoveRange

O(n)

Reverse

O(n)

Sort

O(n log n)

ToArray

O(n)

TrimExcess

O(n)

TrueForAll

O(n)

Stack<T>

Methods

Complexity (for n elements)

Clear

O(n)

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.