<< Click to Display Table of Contents > Example 2 |
![]() ![]() ![]() |
The following C# example shows and measures how much SAMLight Client Control performance constants can accelerate the executed SAMLight Client Control commands. In this case the cursive font, text size, font type and the text content of a Text2D entity with entity name "text entity" are set 100 times as substitute for 100 different text entities to show how SAMLight Client Control performance constants can be used. |
---|
Import necessary namespaces |
---|
using SAMLIGHT_CLIENT_CTRL_OCXLib; using System.Diagnostics; |
Table 455: Import necessary namespaces
As first we will change the text entities without introducing the performance increasing flags. We will make the text in the text entities to be italic and of Arial type, change the size to 20 and change the text of the entities. |
---|
Simple example without performance increase |
---|
//SAMLight Client Control commands to change a text entities: cursive font, //text size, font type; then text content is set //Standard commands without acceleration Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 1; i <= 100; ++i) { cci.ScSetEntityLongData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlags, (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlagItalic); cci.ScSetEntityDoubleData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlDoubleDataIdTextSize, 20); cci.ScSetEntityStringData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlStringDataIdTextFontName,"Arial"); cci.ScChangeTextByName("text entity", "new text"); } stopWatch.Stop(); TimeSpan mt = stopWatch.Elapsed; string MeasuredTime = String.Format("{0:00}.{1:00}", mt.Seconds, mt.Milliseconds); MessageBox.Show("measured time without acceleration: " + MeasuredTime + " s"); stopWatch.Reset(); |
Table 456: Simple example without performance increase
As next we switch on TopLevelOnly and DontUpdateView flags, so that the view is not updated while we change the entity properties and update the view using UpdateViewNow. It decreases the computation time approximately by factor 1.5 - 2.0. |
---|
First example with performance increase (~ 2 x faster) |
---|
//General possibility to accelerate SAMLight Client Control commands by ScSetMode(), //execution speed: ~ 1,5 - 2 0 x faster //We switch on the DontUpdateView and ToplevelOnly modes and do the same, as in the previous step. cci.ScSetMode( (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlModeFlagTopLevelOnly | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlModeFlagDontUpdateView); stopWatch.Start(); for (int i = 1; i <= 100; ++i) { cci.ScSetEntityLongData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlags, (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlagItalic); cci.ScSetEntityDoubleData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlDoubleDataIdTextSize,20); cci.ScSetEntityStringData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlStringDataIdTextFontName,"Arial"); cci.ScChangeTextByName("text entity", "new text"); } cci.ScSetMode(0); cci.ScExecCommand((int) ScComSAMLightClientCtrlExecCommandConstants.scComSAMLightClientCtrlExecCommandUpdateViewNow); stopWatch.Stop(); mt = stopWatch.Elapsed; MeasuredTime = String.Format("{0:00}.{1:00}", mt.Seconds, mt.Milliseconds); MessageBox.Show("measured time with medium acceleration: " + MeasuredTime + " s"); stopWatch.Reset(); |
Table 457: First example with performance increase (~ 2 x faster)
We can do even better by suppressing the entity update and the view update, while executing each particular entity update command. We can do so by accelerating ScSetEntityLongData, ScSetEntityDoubleData, ScSetEntityStringData directly by using additional flags. |
---|
Second example with performance increase (~ 3.5 x faster) |
---|
//Special possibility to accelerate ScSetEntityLongData, ScSetEntityDoubleData or //ScSetEntityStringData commands, execution speed: ~ 3,5 x faster in this example stopWatch.Start(); for (int i = 1; i <= 100; ++i) { cci.ScSetEntityLongData("text entity", (int) ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlags | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateView | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateEntity | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagToplevelOnly, (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdTextCharFlagItalic); cci.ScSetEntityDoubleData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlDoubleDataIdTextSize | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateView | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateEntity | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagToplevelOnly, 20); cci.ScSetEntityStringData("text entity", (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlStringDataIdTextFontName| (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateView | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagDontUpdateEntity | (int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdFlagToplevelOnly, "Arial"); cci.ScChangeTextByName("text entity", "new text"); } stopWatch.Stop(); mt = stopWatch.Elapsed; MeasuredTime = String.Format("{0:00}.{1:00}", mt.Seconds, mt.Milliseconds); MessageBox.Show("measured time with high acceleration: " + MeasuredTime + " s"); stopWatch.Reset(); |
Table 458: <Short Description>
The last command (here: cci.ScChangeTextByName("text entity", "new text")) should not contain DontUpdateEntity or DontUpdateview flags, otherwise the entity will not be updated at all. |
---|