Performance analysis of Enum.Parse vs Enum.TryParse

For the scenerio I am testing, for the below two approaches I found that approach I is better performing than the Approach II.

     //Approach I
            for (int i = 0; i < 100000; i++)
            {
                EnumRepository eRepository1 = (EnumRepository)Enum.Parse(typeof(ECCRepository), "GHOUSE");
            }
           
            //Approach II
            for (int i = 0; i < 100000; i++)
            {
                EnumRepository eRepository;
                Enum.TryParse("GHOUSE", out eRepository);
            }

            stopwatch.Stop();
            long timespan1 = stopwatch.ElapsedTicks;
            TimeSpan timespan2 = stopwatch.Elapsed;

            Console.WriteLine("Time taken:" + timespan1);

Comments

Popular posts from this blog

Convert XElement to DataTable

Enable mouse scroll-wheel in VB6

C# code to Check IE Proxy Settings