Bonjour à tous.
Aujourd'hui je requiers votre aide pour comparer la performance de 2 méthodes (temps d'utilisation et charge du CPU).
Dans le code suivants, je dois donc afficher les ressources CPU utilisées dans le moniteur de performance pour les méthodes "GenerateTIFF_Aspose" et "GenerateTIFF_Spire".
J'utilise les Task en parallélisme pour afficher les résultats en synchro parfaite dans le moniteur de performance. Je n'ai pas utilisé les performance counter depuis pas mal de temps, j'ai un peu de mal aujourd'hui
Merci !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace TestConverter { public class Program { /* COMPTEUR DE PERFORMANCE */ // Aspose private static Boolean isCounterCreated_Aspose = false; private static PerformanceCounter cpuCounter_Aspose; private static PerformanceCounter ramCounter_Aspose; private static Boolean TestDone_Aspose = false; private static Task test_Aspose = Task.Factory.StartNew(() => GenerateTIFF_Aspose()); // Spire private static Boolean isCounterCreated_Spire = false; private static PerformanceCounter cpuCounter_Spire; private static PerformanceCounter ramCounter_Spire; private static Boolean TestDone_Spire = false; private static Task test_Spire = Task.Factory.StartNew(() => GenerateTIFF_Spire()); static void Main(string[] args) { isCounterCreated_Aspose = SetupCategory_Aspose(); if (isCounterCreated_Aspose) { CreateCounters_Aspose(); } isCounterCreated_Spire = SetupCategory_Spire(); if (isCounterCreated_Spire) { CreateCounters_Spire(); } Task.WaitAll(test_Aspose, test_Spire); } #region PERFORMANCE COUNTER - ASPOSE private static bool SetupCategory_Aspose() { // CPU switch (PerformanceCounterCategory.Exists("ChargeCPUCategory_Aspose")) { case true: Console.WriteLine("Performance Counter - La catégorie existe déjà !"); return false; break; case false: CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection(); // Ajout du compteur CounterCreationData chargeCPU = new CounterCreationData(); chargeCPU.CounterType = PerformanceCounterType.AverageBase; chargeCPU.CounterName = "Charge"; counterDataCollection.Add(chargeCPU); // Ajout du compteur de BASE CounterCreationData tempsCPU = new CounterCreationData(); tempsCPU.CounterType = PerformanceCounterType.AverageBase; tempsCPU.CounterName = "Temps"; counterDataCollection.Add(tempsCPU); // Ajout de la catégorie PerformanceCounterCategory.Create("ChargeCPUCategory_Aspose", "Analyse de la charge du CPU pour ASPOSE.", PerformanceCounterCategoryType.SingleInstance, counterDataCollection); return true; break; } // RAM switch (PerformanceCounterCategory.Exists("ChargeRAMCategory_Aspose")) { case true: Console.WriteLine("Performance Counter - La catégorie existe déjà !"); return false; break; case false: CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection(); // Ajout du compteur CounterCreationData chargeRAM = new CounterCreationData(); chargeRAM.CounterType = PerformanceCounterType.AverageBase; chargeRAM.CounterName = "Charge"; counterDataCollection.Add(chargeRAM); // Ajout du compteur de BASE CounterCreationData tempsCPU = new CounterCreationData(); tempsCPU.CounterType = PerformanceCounterType.AverageBase; tempsCPU.CounterName = "Temps"; counterDataCollection.Add(tempsCPU); // Ajout de la catégorie PerformanceCounterCategory.Create("ChargeRAMCategory_Aspose", "Analyse de la charge de la RAM pour ASPOSE.", PerformanceCounterCategoryType.SingleInstance, counterDataCollection); return true; break; } return false; } private static void CreateCounters_Aspose() { cpuCounter_Aspose = new PerformanceCounter(); cpuCounter_Aspose.CategoryName = "ChargeCPUCategory_Aspose"; cpuCounter_Aspose.CounterName = "% Processor Time"; cpuCounter_Aspose.InstanceName = "_Total"; cpuCounter_Aspose.RawValue = 0; ramCounter_Aspose = new PerformanceCounter(); ramCounter_Aspose.CategoryName = "ChargeRAMCategory_Aspose"; ramCounter_Aspose.CounterName = "Physical Memory"; ramCounter_Aspose.InstanceName = "_Total"; ramCounter_Aspose.RawValue = 0; } private static void RunTest_Aspose() { while (!TestDone_Aspose) { cpuCounter_Aspose.NextValue(); ramCounter_Aspose.NextValue(); Thread.Sleep(100); } } #endregion #region PERFORMANCE COUNTER - SPIRE private static bool SetupCategory_Spire() { // CPU switch (PerformanceCounterCategory.Exists("ChargeCPUCategory_Spire")) { case true: Console.WriteLine("Performance Counter - La catégorie existe déjà !"); return false; break; case false: CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection(); // Ajout du compteur CounterCreationData chargeCPU = new CounterCreationData(); chargeCPU.CounterType = PerformanceCounterType.AverageBase; chargeCPU.CounterName = "Charge"; counterDataCollection.Add(chargeCPU); // Ajout du compteur de BASE CounterCreationData tempsCPU = new CounterCreationData(); tempsCPU.CounterType = PerformanceCounterType.AverageBase; tempsCPU.CounterName = "Temps"; counterDataCollection.Add(tempsCPU); // Ajout de la catégorie PerformanceCounterCategory.Create("ChargeCPUCategory_Spire", "Analyse de la charge du CPU pour Spire.", PerformanceCounterCategoryType.SingleInstance, counterDataCollection); return true; break; } // RAM switch (PerformanceCounterCategory.Exists("ChargeRAMCategory_Spire")) { case true: Console.WriteLine("Performance Counter - La catégorie existe déjà !"); return false; break; case false: CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection(); // Ajout du compteur CounterCreationData chargeRAM = new CounterCreationData(); chargeRAM.CounterType = PerformanceCounterType.AverageBase; chargeRAM.CounterName = "Charge"; counterDataCollection.Add(chargeRAM); // Ajout du compteur de BASE CounterCreationData tempsCPU = new CounterCreationData(); tempsCPU.CounterType = PerformanceCounterType.AverageBase; tempsCPU.CounterName = "Temps"; counterDataCollection.Add(tempsCPU); // Ajout de la catégorie PerformanceCounterCategory.Create("ChargeRAMCategory_Spire", "Analyse de la charge de la RAM pour Spire.", PerformanceCounterCategoryType.SingleInstance, counterDataCollection); return true; break; } return false; } private static void CreateCounters_Spire() { cpuCounter_Spire = new PerformanceCounter(); cpuCounter_Spire.CategoryName = "ChargeCPUCategory_Spire"; cpuCounter_Spire.CounterName = "% Processor Time"; cpuCounter_Spire.InstanceName = "_Total"; cpuCounter_Spire.RawValue = 0; ramCounter_Spire = new PerformanceCounter(); ramCounter_Spire.CategoryName = "ChargeRAMCategory_Spire"; ramCounter_Spire.CounterName = "Physical Memory"; ramCounter_Spire.InstanceName = "_Total"; ramCounter_Spire.RawValue = 0; } private static void RunTest_Spire() { while (!TestDone_Spire) { cpuCounter_Spire.NextValue(); ramCounter_Spire.NextValue(); Thread.Sleep(100); } } #endregion #region Test des méthodes public static void GenerateTIFF_Aspose() { Aspose.Words.Document doc = new Aspose.Words.Document("C:\\Users\\MAY\\Downloads\\ASPOSE_IN.doc"); Aspose.Words.Saving.ImageSaveOptions options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Tiff); options.PageIndex = 0; options.PageCount = 2; options.TiffCompression = Aspose.Words.Saving.TiffCompression.Ccitt4; options.Resolution = 320; doc.Save("C:\\Users\\MAY\\Downloads\\ASPOSE_OUT.tiff", options); TestDone_Aspose = true; } public static void GenerateTIFF_Spire() { Spire.Doc.Document doc = new Spire.Doc.Document(); doc.LoadFromFile("C:\\Users\\MAY\\Downloads\\SPIRE_IN.doc"); Image image = doc.SaveToImages(0, Spire.Doc.Documents.ImageType.Bitmap); image.Save("C:\\Users\\MAY\\Downloads\\SPIRE_OUT.tiff", ImageFormat.Tiff); TestDone_Spire = true; } #endregion } }






Répondre avec citation


tu vas me dire j'ai pas lu le code, c'est vrai (252 lignes)... tu ferais pas mieux d'en lancer une puis l'autre
Partager