11using System ;
2+ using System . Configuration ;
23using System . Linq ;
34
45namespace SharpBenchmark . Samples
@@ -9,14 +10,23 @@ static void Main(string[] args)
910 {
1011 var allSamples = typeof ( ISample ) . Assembly . GetTypes ( ) ;
1112
13+
14+
15+
1216 while ( true )
1317 {
14- Console . Write ( "Which sample would you like to run? (enter q to quit): " ) ;
18+ Console . Write ( "Which sample would you like to run? (enter q to quit, enter load to load a dll ): " ) ;
1519 var input = Console . ReadLine ( ) ;
1620
1721 if ( input == "q" || input == null )
1822 break ;
1923
24+ if ( input == "load" )
25+ {
26+ LoadDll ( ) ;
27+ continue ;
28+ }
29+
2030 var parts = input . Split ( ' ' ) ;
2131 var sampleNum = 0 ;
2232 if ( ! Int32 . TryParse ( parts [ 0 ] , out sampleNum ) )
@@ -42,5 +52,79 @@ static void Main(string[] args)
4252 sample . Execute ( tmp . ToArray ( ) ) ;
4353 }
4454 }
55+
56+ static void LoadDll ( )
57+ {
58+ Console . WriteLine ( "Full Path to DLL (or blank to use testing DLL): " ) ;
59+ var path = Console . ReadLine ( ) ;
60+ //Console.WriteLine("Full Path to DLL: ");
61+ if ( String . IsNullOrEmpty ( path ) )
62+ path = @"C:\Projects\SharpBenchmark\SharpBenchmark.ExampleDll\bin\Debug\SharpBenchmark.ExampleDll.dll" ;
63+
64+ if ( ! String . IsNullOrEmpty ( path ) )
65+ {
66+ var dll = System . Reflection . Assembly . LoadFrom ( path ) ;
67+
68+ var types = dll . GetTypes ( ) ;
69+
70+ Console . WriteLine ( "Types in the DLL" ) ;
71+ Console . WriteLine ( "-------------------------" ) ;
72+
73+ var i = 1 ;
74+ foreach ( var type in types )
75+ {
76+ Console . WriteLine ( "{0}) {1} " , i , type . FullName ) ;
77+
78+ i ++ ;
79+ }
80+
81+ Console . WriteLine ( ) ;
82+ Console . WriteLine ( "Enter the number of the type you'd like to use: " ) ;
83+ var input = Console . ReadLine ( ) ;
84+
85+ var typeNum = Int32 . Parse ( input ) ;
86+ var selectedType = types [ typeNum - 1 ] ;
87+
88+ Console . WriteLine ( ) ;
89+ Console . WriteLine ( "Methods in this type" ) ;
90+ Console . WriteLine ( "-------------------------" ) ;
91+
92+ // get all public methods
93+ i = 1 ;
94+ var methods = selectedType . GetMethods ( ) ;
95+ foreach ( var method in methods )
96+ {
97+ Console . Write ( "{0}) {1}(" , i , method . Name ) ;
98+
99+ foreach ( var pi in method . GetParameters ( ) )
100+ {
101+ Console . Write ( "{0} {1}, " , pi . ParameterType , pi . Name ) ;
102+ }
103+
104+ Console . WriteLine ( ")" ) ;
105+ i ++ ;
106+ }
107+
108+ Console . WriteLine ( ) ;
109+ Console . WriteLine ( "Enter the number(s) of the method you'd like to use: " ) ;
110+ input = Console . ReadLine ( ) ;
111+
112+ var benchmarker = new Benchmarker ( ) ;
113+
114+ foreach ( var methodNum in input . Split ( ',' ) . Select ( x => Int32 . Parse ( x . Trim ( ) ) ) )
115+ {
116+ var selectedMethod = methods [ methodNum - 1 ] ;
117+
118+ // create an action with this method
119+ // TODO: make this work with methods that have parameters, right now it won't
120+ var newType = Activator . CreateInstance ( selectedType ) ;
121+ var del = ( Action ) Delegate . CreateDelegate ( typeof ( Action ) , newType , selectedMethod ) ;
122+
123+ benchmarker . AddTest ( selectedMethod . Name , del ) ;
124+ }
125+
126+ benchmarker . RunTests ( 20 ) ;
127+ }
128+ }
45129 }
46130}
0 commit comments