From: Deyan P. <de...@ho...> - 2004-10-28 15:48:08
|
Hi hammett, Great, thanks a lot for the modification!!! Now it looks really great. I have currently implemented a project with explicit proxies for lazy-loading, and I am thinking of replacing them with the more transparent Dynamic Proxies, that's why I am delving into the stuff... I did some tests and the results are a little bit strange ... I have changed the retrieval of the objects, so that they are loaded from the db now. The full code is here: http://www20.brinkster.com/deyanp/dynproxy/DynamicProxyAvalonTest.zip Class1.cs looks now like this: using System; namespace DynamicProxyAvalonTest { class Class1 { [STAThread] static void Main(string[] args) { Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Console.ReadLine(); } public static void Test(int maxi, int maxj, bool useProxy) { int start = Environment.TickCount; int i = 0; int j = 0; for(i=0;i<maxi;i++) { //useProxy=true lazy-loads the referenced country //a dynamic proxy is stuffed in //altogether 2 db calls: 1 for the user //and later 1 for the country //useProxy=false eager-loads the referenced country //the country is directly retrieved from the db upon retrieval of the user //in a separate db call //altogether 2 db calls: 1 for the user //and immediately another 1 for the country User user = UserDA.Select(1830, useProxy); for(j=0;j<maxj;j++) { int d = user.ID; string n = user.Name; if(user.Country != null) { int d2 = user.Country.ID; string n2 = user.Country.Name; } } } int end = Environment.TickCount; Console.WriteLine(String.Format("Loop[i={0},j={1}] useProxy={2} Test:\t\t\t{3}", i, j, useProxy, end - start)); } } } The results are the following: Loop[i=1000,j=1] useProxy=True Test: 1219 Loop[i=1000,j=1] useProxy=False Test: 781 Loop[i=1000,j=1] useProxy=True Test: 890 Loop[i=1000,j=1] useProxy=False Test: 782 Loop[i=1000,j=1] useProxy=True Test: 890 Loop[i=1000,j=1] useProxy=False Test: 813 Loop[i=1000,j=1] useProxy=True Test: 906 Loop[i=1000,j=1] useProxy=False Test: 812 Loop[i=1000,j=100] useProxy=True Test: 1485 Loop[i=1000,j=100] useProxy=False Test: 734 Loop[i=1000,j=100] useProxy=True Test: 1406 Loop[i=1000,j=100] useProxy=False Test: 719 Loop[i=1000,j=100] useProxy=True Test: 1406 Loop[i=1000,j=100] useProxy=False Test: 766 Loop[i=1000,j=100] useProxy=True Test: 1437 Loop[i=1000,j=100] useProxy=False Test: 766 Loop[i=1000,j=1000] useProxy=True Test: 5859 Loop[i=1000,j=1000] useProxy=False Test: 813 Loop[i=1000,j=1000] useProxy=True Test: 5859 Loop[i=1000,j=1000] useProxy=False Test: 813 Loop[i=1000,j=1000] useProxy=True Test: 5843 Loop[i=1000,j=1000] useProxy=False Test: 922 Loop[i=1000,j=1000] useProxy=True Test: 6031 Loop[i=1000,j=1000] useProxy=False Test: 891 It seems that the inner loop causes performance problems - if the value is 1 then there is almost no difference between the proxy and no proxy versions, but if it is 1000, then the difference is 6x. Let me know what you think about this, if you find time for that. I will continue investigating the issue tomorrow. Best regards, Deyan |