performance of get_cellsU() in dotnet

M

Matthias Cavigelli

Hi newsgroup

I am programming a Class Library in CSharp, which highly interacts with
Visio 2002.

Each shape in a selection needs to be replaced. So I drop a master for
each item in that selection, then copying the Shape Transformation
Section from the old shape to the new one. I notice that sometimes my
CSharp Library needed 4-8 times longer to do the task, compared to a VBA
solution.

I disabled the undo property of the application, which only cut
execution time by about 10%. I went on and think that I have found the
culprit: get_cellssrc calls. I changed get_cellssrc calls to get_cells
calls, however no major difference in my tests.

I made two tests, each in VBA and CSharp (source below):

== Test 1: Dropping a master for each shape in the selection
5 x 234(amount of shapes in selection)
VBA: 4, 4, 4, 5, 5 [seconds] -> av: 4.4
CSharp 2, 3, 3, 3, 4 [seconds] -> av: 3
The VBA could be optimized a little more, however more or less same
performance and not really significant differences.

== Test 2: Same as Test 1 but also copying Shape Transformation Section
from shape in selection to new shape(-> calling many times getcellsU())
VBA: 6, 9, 6, 6, 9 [seconds] -> av: 7.2
CSharp 26, 30, 40, 38, 35 [seconds] -> av: 33.8!!!!!!
Breakdown of .Net / CSharp solution, CSharp 450% slower!!!!!!

I use the .Net Framework 1.0, the Office PIA and Visio 2002 SR-1. All
tests were made on the same computer and in the same document.

Has anybody made similar experiences? What are the workarounds?
I cannot believe, that there is such a dramatic difference. What is
wrong with my solution?

Thanks for any help

Matthias, a little desperate:-(


====CSharp code=======================

private static void TestControl(bool copySection, Visio.Selection sel){
const int LOOPS = 5;
string msg = "";
DateTime start = new DateTime();
DateTime stop = new DateTime();
TimeSpan delta = new TimeSpan();
Visio.Master mst =
sel.Application.ActiveDocument.Masters[3];
Visio.Page apg = sel.Application.ActivePage;
for(int i = 0; i < LOOPS; i++){
start = DateTime.Now;
TransformSelection(copySection, sel, mst, apg);
stop = DateTime.Now;
delta = stop - start;
msg +=delta.Minutes + ": " + delta.Seconds + "\n";
}
System.Windows.Forms.MessageBox.Show(msg);
}

private static void TransformSelection(bool copySection,
Visio.Selection sel, Visio.Master mst, Visio.Page pg){
Visio.Shape shpNew;
foreach(Visio.Shape shpOld in sel){
shpNew = pg.Drop(mst, 0, 0);
if(copySection){
CopyShapeTransformationSection(shpOld, shpNew);
}
}
}

private static void CopyShapeTransformationSection(Visio.Shape
shpOld, Visio.Shape shpNew){
string[] cellNames = new string[]{"PinX", "PinY", "Width",
"Height", "LocPinX",
"LocPinY", "Angle",
"FlipX", "FlipY", "ResizeMode"};
foreach(string cellName in cellNames){
shpNew.get_CellsU(cellName).Formula =
shpOld.get_CellsU(cellName).Formula;
}
}

===VBA=======================
Public Sub WithCellsU()
Call TestControl(True)
End Sub

Public Sub NoCellsU()
Call TestControl(False)
End Sub

Private Sub TestControl(copySection As Boolean)
Const LOOPS As Integer = 5
Dim msg As String
Dim startDate As Date
Dim stopDate As Date
Dim deltaDate As Date
Dim mst As Visio.Master
Dim pg As Visio.page
Dim sel As Visio.Selection
Dim i As Integer

msg = ""
Set sel = ActiveWindow.Selection
Set mst = ActiveDocument.Masters(3)
Set pg = ActivePage

For i = 0 To LOOPS - 1
startDate = Now
Call TransformSelection(copySection, sel, mst, pg)
stopDate = Now
deltaDate = stopDate - startDate
msg = msg & Minute(deltaDate) & ": " & Second(deltaDate) &
vbNewLine
Next i
MsgBox msg
End Sub

Private Sub TransformSelection(copySection As Boolean, sel As
Visio.Selection, mst As Visio.Master, pg As Visio.page)
Dim shpNew As Visio.Shape
Dim shpVar As Variant
For Each shpVar In sel
Set shpNew = pg.Drop(mst, 0, 0)
If copySection Then
Call CopyShapeTransformations(shpVar, shpNew)
End If
Next shpVar

End Sub

Private Sub CopyShapeTransformations(shpOld As Variant, shpNew As
Visio.Shape)
Dim cellNames(9) As String
Dim cellName As Variant

cellNames(0) = "PinX"
cellNames(1) = "PinY"
cellNames(2) = "Width"
cellNames(3) = "Height"
cellNames(4) = "LocPinX"
cellNames(5) = "LocPinY"
cellNames(6) = "Angle"
cellNames(7) = "FlipX"
cellNames(8) = "FlipY"
cellNames(9) = "ResizeMode"
With shpNew
For Each cellName In cellNames
.CellsU(cellName).Formula = shpOld.CellsU(cellName).Formula
Next cellName
End With
End Sub
 
M

Markus Breugst

Hello Matthias,
Has anybody made similar experiences?

Yes, indeed! We are also implementing a C# application that interacts with
Visio, and we also have performance problems.
What are the workarounds?

Here are links to two newsgroup contributions that may be interesting for
you. The first one gives several hints concerning performance improvements,
and the second one describes how to combine multiple method invocations for
setting cell values into a single one. (The main issue is probably the fact
that every interaction between your application and Visio has to cross
process boundaries.)

http://groups.google.de/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&threadm=ObhBJsCWC
HA.2540%40tkmsftngp09&rnum=2&prev=/groups%3Fq%3Dvisio%2Bperformance%2Bshapes
%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DObhBJsCWCHA.2540%2540t
kmsftngp09%26rnum%3D2

http://groups.google.de/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&threadm=#m0hwr0
dAHA.2108%40tkmsftngp03&rnum=16&prev=/groups%3Fq%3Dvisio%2Bperformance%2Bpro
blem%26start%3D10%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D%2523
m0hwr0dAHA.2108%2540tkmsftngp03%26rnum%3D16

Hope, this information helps. If you find any other possibilities of
performance tuning, I would be glad to read about them.

Best regards,
Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top