|
using System;
using System.Collections;
using System.Threading;
namespace DynamicProxyTutorial
{
/// <summary>
/// Proxy Performance tester
/// </summary>
public class Performance
{
public int instancesToTest = 1000000;
public int gcWaitTime = 5000;
public double milliSecondsToCreateHandProxy;
public double milliSecondsToCreateDynamicProxy;
public double milliSecondsToCallGetContentHandProxy;
public double milliSecondsToCallGetContentDynamicProxy;
public Performance() {
}
public void test() {
testHandProxyInstances();
testDynamicProxyInstances();
testHandProxyInvocations();
testDynamicProxyInvocations();
}
private void prepareForTest() {
// Run the GC and wait for it to (hopefully) be done
System.GC.Collect();
Thread.Sleep(gcWaitTime);
}
private void testHandProxyInstances() {
prepareForTest();
DateTime startTime = DateTime.Now;
for (int count = 0; count < instancesToTest; count++) {
IFileViewer fileViewer = FileViewerProxyFactory.createProxy("", "", false);
fileViewer = null;
}
DateTime endTime = DateTime.Now;
TimeSpan diff = endTime.Subtract(startTime);
milliSecondsToCreateHandProxy = timeDiff(startTime, endTime);
}
private void testDynamicProxyInstances() {
prepareForTest();
DateTime startTime = DateTime.Now;
for (int count = 0; count < instancesToTest; count++) {
IFileViewer fileViewer = FileViewerProxyFactory.createProxy("", "", true);
fileViewer = null;
}
DateTime endTime = DateTime.Now;
TimeSpan diff = endTime.Subtract(startTime);
milliSecondsToCreateDynamicProxy = timeDiff(startTime, endTime);
}
private void testHandProxyInvocations() {
prepareForTest();
DateTime startTime = DateTime.Now;
IFileViewer fileViewer = FileViewerProxyFactory.createProxy("", "", false);
String valueHolder;
for (int count = 0; count < instancesToTest; count++) {
valueHolder = fileViewer.Content;
}
DateTime endTime = DateTime.Now;
TimeSpan diff = endTime.Subtract(startTime);
milliSecondsToCallGetContentHandProxy = timeDiff(startTime, endTime);
}
private void testDynamicProxyInvocations() {
prepareForTest();
DateTime startTime = DateTime.Now;
IFileViewer fileViewer = FileViewerProxyFactory.createProxy("", "", true);
String valueHolder;
for (int count = 0; count < instancesToTest; count++) {
valueHolder = fileViewer.Content;
}
DateTime endTime = DateTime.Now;
TimeSpan diff = endTime.Subtract(startTime);
milliSecondsToCallGetContentDynamicProxy = timeDiff(startTime, endTime);
}
private double timeDiff(DateTime startTime, DateTime endTime) {
TimeSpan diff = endTime.Subtract(startTime);
return (double)((double)(diff.Hours*60*60*1000 + diff.Minutes*60*1000 + diff.Seconds*1000 + diff.Milliseconds))/(double)instancesToTest;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here