.NET news » Performance Performance Rss Feed

download
Performance Quiz #9 : IList List and array speed -- solution

In the test case as given there's a great deal of repeated work extracting the length of the array and accessing the items. This is because of the unusual property that arrays have -- they implement IList for potetially more than one T even due to inheritance. In the interest of economy alone then it is worthwhile to consolidate the IList implementations into some kind of secret helper but this has some consequences.

Short results:

Test Case Milliseconds
Test1: Array 54
Test2: List<> 8
Test3: ArrayWrapper 14
Test4: Array via foreach 9
Test5: List<> via foreach 11
Test6: Array via special 6
Test7: List<> via special 8
12 Mar 2006, 08:46:00   Source: Performance Quiz #9 : IList List and array speed --...   Tags: Performance
Performance Quiz #9 : IList<T> List and array speed

A short and sweet quiz with lots of juicy discussion possibilities:

public int Sum(IList<ushort> indices)
{
int result = 0;
for (int i = 0; i < indices.Count; i++)
result += indices[i];
return result;
}

Considering only the time it takes to do the Sum (i.e. assuming we had already set up the array/list) which gives better performance and why?

// #1
ushort[] tmp = new ushort[500000]; // this doesn't count
Sum(tmp);// this is what we are timing

OR

// #2
List<ushort> tmp = new List<ushort>(500000); // this doesn't count
for (int i = 0; i < 500000; i++)tmp.Add(0); // this doesn't count
Sum(tmp); // this is what we are timing

What say you gentle readers?

9 Mar 2006, 18:31:00   Source: Performance Quiz #9 : IList<T> List and array speed   Tags: Performance C#
Built For Speed: Develop Turbocharged Apps For Windows Compute Cluster Server
This article explores the services provided by Compute Cluster Server 2003 and the tools provided by Visual Studio 2005 that will help you develop High-Perfomance Computing applications.
.NET Profiling: Write Profilers With Ease Using High-Level Wrapper Classes
Here Joachim H. Fröhlich and Reinhard Wolfinger show you how to get all the great functionality of the .NET Profiling API the easy way, with custom wrappers.
8 Mar 2006, 18:00:00   Source: .NET Profiling: Write Profilers With Ease Using...   Tags: Performance Testing
CLR Inside Out: Extending System.Diagnostics
CLR Inside Out: Extending System.Diagnostics
8 Mar 2006, 18:00:00   Source: CLR Inside Out: Extending System.Diagnostics   Tags: Debug Performance
An O(ND) Difference Algorithm for C#
This article is about comparing text files, and the proven, best, and most famous algorithm to identify the differences between them.
6 Mar 2006, 09:58:00   Source: An O(ND) Difference Algorithm for C#   Tags: Performance
Full-Text Search: Fast, Damn Fast and DotLucene
DotLucene Demo: Search 3.5 GB of text in 0.1 second!
6 Mar 2006, 08:26:00   Source: Full-Text Search: Fast, Damn Fast and DotLucene   Tags: Performance Components
Get Control and Performance with the Real Time Stylus API
The Real Time Stylus API provides an alternate way to receive pen input pen. This high performance API provides a great level of control to developers for a small penalty in added effort.
Xenocode Postbuild 2006 allows .NET applications to run anywhere
Xenocode Postbuild 2006 breakthrough technology allows .NET applications to run on any Windows PC, with or without the Framework, counteracts decompilation and reverse engineering, optimizes application size and performance, and dramatically reduces test and support costs by eliminating "DLL/versioning hell".
Fast/Compact Serialization Framework
A simple and fast way of "serializing objects by value" to compact binary representations.
22 Feb 2006, 15:13:00   Source: Fast/Compact Serialization Framework   Tags: C# Examples Performance