(string)XlCall.Excel( XlCall.xlfGetCell, (int)GetCellType.Text, excelReference )
Run | C API GetValue() (3) | Interop Range.Value2 | Interop Range.Value | Interop Range.Value/Loop (1) | VBA/Loop (1) | C API Looping/GetCell (1) | COM (Application.Run) (1) | Interop Loop/Text (1) |
1 | 0.3507217 | 0.7069541 | 0.9426819 | 1.6121424 | 20.5388871 | 19.6186631 | 22.3122662 | 72.5640065 |
2 | 0.3614963 | 0.7421369 | 0.9145262 | 1.5115977 | 19.9144984 | 19.2103384 | 21.2756509 | 70.8351868 |
3(2) | 0.35609931 | 0.719151943 | 0.925460836 | 1.557100406 | 22.6988244 | 23.0396793 | 23.624186 | 82.022291 |
4(2) | 0.351611989 | 0.731355898 | 0.923744209 | 1.558899742 | 17.7283302 | 21.2414558 | 23.3982391 | 81.0125688 |
5(2) | 0.353727928 | 0.728213728 | 0.923501217 | 1.550801263 | 22.1358615 | 22.5800253 | 23.242252 | 81.1945079 |
Average | 0.354731445 | 0.725562514 | 0.925982872 | 1.558108302 | 20.60328032 | 21.13803238 | 22.77051884 | 77.5257122 |
Hi Terry,
Thanks for posting this!
It does seem to confirm that the C API is significantly faster than the COM object model, where it does apply.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
And I generate an Xml structure that looks like this:
In my VBA version, it took 246 seconds to complete... in C#/DNA it took 0.6 seconds!!
I didn't even know it was possible to create a 10MB file in 0.6 seconds. Obviously, the code was written 'better' (in general) and also better in terms of using C# functionality that isn't available in VBA, but I am still amazed.
The results were a little surprising to me (but perhaps I am doing something wrong). For ~190K cells, the time to serialize it to XML was just over a second (which was slower than I expected) and then the performance of the LINQ queries and DataTable construction is good (128 ms).
1010 ms to get XML selection
1139 ms to generate XML document
7 columns 27440 rows 1267 ms total
Stopwatch stopwatch = Stopwatch.StartNew();
var reference = new ExcelReference( ... ); // I had a reference passed in, but just putting this here as example
var data = reference.GetRange().Value; // GetRange() was extension method to just take ExcelReference address information and grab the same cells as a MS Office Range
// Reference was only 1 cell if null, so not an object[,] but actual value, so change to array
var value = data as object[,] ?? new object[,] { { data } };
return new InteropArray( value );
/// <summary>
/// Wrapper for Microsoft Interop Arrays that are 1 based to make accessing them
/// via C# 0 based arrays work.
/// </summary>
public class InteropArray
{
private object[,] data;
public int Rows { get; private set; }
public int Columns { get; private set; }
private int rowOffset;
private int colOffset;
public InteropArray( object[,] data )
{
this.data = data;
Rows = data.GetLength( 0 );
Columns = data.GetLength( 1 );
// If GetArray is called on single cell, c# creates the
// array instead of Excel and it is 0 based.
rowOffset = data.GetLowerBound( 0 );
colOffset = data.GetLowerBound( 1 );
}
public object this[ int x, int y ]
{
get
{
return data[ x + rowOffset, y + colOffset ];
}
}
}