|
.Net WPF MakeChart performance, image vs winformHost ? |
Posted by Mathieu on Aug-12-2011 00:53 |
|
Hi,
I am trying ChartDirector for .Net to add two piecharts in my WPF project.
I see two choices, I can either use a winformsHost and host a WinChartViewer or I can
simple generate an ImageSource (and then bind it).
So I went for the "generate an ImageSource" option and did something like this to create
the ImageSource.
byte[] buffer = c.makeChart2(ChartDirector.Chart.BMP);
using (MemoryStream bitmapStream = new MemoryStream(buffer))
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = bitmapStream;
bitmapImage.CreateOptions = BitmapCreateOptions.None;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
ImageSource chartFinalSource = bitmapImage as ImageSource;
chartFinalSource.Freeze();
return chartFinalSource;
}
But I realise the call to c.makeChart2 is really heavy in the processing, and considering I
want to update 2 graphs as much as possible (minimally every 1.5seconds).
Would the option of the winformHost control be much more efficient or similar in terms of
processing performance? |
Re: .Net WPF MakeChart performance, image vs winformHost ? |
Posted by Peter Kwan on Aug-13-2011 01:10 |
|
Hi Mathieu,
The makeChart2 itself should take less than 100ms (probably a lot less).
I have not tested what is the speed for the code in the "using {....}", and for the WPF GUI to finally display the bitmapImage. However, intuitively, I would think your code is faster than the winformHost. Also, I suspect you should be able to update 2 pie charts per second easily.
May be you can perform some performance test to see if the performance is acceptable for your case. To do a performance test, you may:
(a) Use DateTime.Ticks in your code to get the ticks at various lines in your code. You can then know the CPU time used by various parts of your code.
(b) Remember to perform the test in "Release mode".
(c) Remember to use "Run without Debugging" for performance test. If debugging is used, the speed can be significantly lower even in release mode.
(d) When the code is run the first few times, the .NET system is just loading the code from the assembly on demand, and the Just In Time compiler is compiling the byte code into native code. So the timing is not accurate - it includes the assembly loading time and the JIT compilation time. After iterating the code for a few times, the timing should stablise and it is the real timing.
Regards
Peter Kwan |
Re: .Net WPF MakeChart performance, image vs winformHost ? |
Posted by Mathieu on Aug-15-2011 20:56 |
|
Thank you for your advices. |
|