Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Context: http://stackoverflow.com/questions/35995466/best-perfomance-option-to-instantiate-class-from-string
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- var _stopWatch = new Stopwatch();
- var times = new List<long>();
- var iterations = 200000;
- _stopWatch.Start();
- for( int i = 0;i < iterations;i++ )
- {
- var t1 = ViewModelFactory.CreateInstance( "CursosViewModel", "", "", "", 0 );
- }
- _stopWatch.Stop();
- times.Add( _stopWatch.ElapsedMilliseconds );
- _stopWatch.Restart();
- for( int i = 0;i < iterations;i++ )
- {
- var type = Type.GetType( "Site.ViewModels.CursosViewModel" );
- var obj = Activator.CreateInstance( type, new object[] { "", "", "", 0 } );
- }
- _stopWatch.Stop();
- times.Add( _stopWatch.ElapsedMilliseconds );
- _stopWatch.Restart();
- for( int i = 0;i < iterations;i++ )
- {
- var type = HtmlParser.GetClassType( "CursosViewModel" );
- }
- _stopWatch.Stop();
- times.Add( _stopWatch.ElapsedMilliseconds );
- return View( times );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement