.net Worksheet Function Performance
Here is a performance table for a moderately complex array formula I converted to various types of Visual Studio (2003) project:
| Performance (Excel 2003) |
| 57,000 formulas, calculated 10 times |
| Version |
Time |
Performance |
| |
Seconds |
% of Excel |
| Excel |
27 |
100% |
| VBA |
29 |
107% |
| VB6 |
32 |
119% |
| C# |
260 |
963% |
| C++ (XLL+) |
13 |
48% |
Here is the worksheet function that was converted (it returns the last non zero value from a list of 100 values):
{=INDEX(B1:B104,MAX(ROW(B4:B104)*(B4:B104<>0)))}
If you would like the full set of projects to play with then let us know. The C++ one was written with the help of XLL+ from Planatech so you will need a demo copy of that. In fact you can download a Zip with an instruction doc, a test workbook, and the VB6 VBA and C# source code here (1.5Mb). You will need Visual Studio 6 for the VB version and 2003 for the C# one (it may work in other versions - let us know).
All the programmed solutions benefited from using a specific algorithm suited to the problem. The performance difference would be quite different for any other problem. The likely outcome being Excel and C++ much closer and VBA/VB6 further behind. C# unfortunately, would probably never make the grade.
The VBA one was compiled, and the IDE closed before running. The VB6 version had all speed optimisations set. I did not bother with a VB.net version as there seems no reason to believe it would be materially faster than C#.
The C# code is significantly different to the other code as it needs an Excel reference to be able to understand the range that is passed in. In VB6 and VBA that is treated as a variant, and looped through in the normal way. However, simply adding 2 doubles (ie no Excel objects) in the above manner takes 30 seconds in C#, so its not just the Excel reference, if at all (Excel comparison time? 0 seconds rounded to 0 decimal places!). |