Geeks With Blogs

News Ashraful Alam Joy

Create Your Badge

Ashraful Alam is a Software Architect, who has 8 years of professional experience in Software Development industry. This Bangladeshi national is involved with project management and development of several US based software projects from his country. Already he has managed and developed several software projects, which are being used by several users of different countries, such as USA, Canada, Australia, and Bangladesh. While developing and managing a team, he contains and maintains a set of well defined engineering practices developed by him and other online developer communities.

Due to his willingness to give effort to improve and share better software development practices, Ashraf has been awarded as “Most Valuable Professional” (MVP) in ASP.NET category by Microsoft since year 2007 multiple times, which is a rare honor and prestigious reorganization among the developers around the world.

Check his portfolio to know more about him and his works.


.NETTER Characters... Every part of your life is best, if you can know yourself and thus create your life like an artist!

Performance is a one of the basic requirements in the most of the current trend of web applications. While designing software architecture, there are several technologies kept available for the designers. Among these available options, some of techniques may includes multiple solutions, combining of those can create a case, where the basic performance output can't be determined based on the common sense and/or in depth knowledge on the corresponding topics. In short, based upon different options the software architect needs to determine the appropriate object model which fits best with the current application requirement.

The Object Model

There are three layers of our test framework object model, as follows:

The Program Class: This is the starter class, which creates the requires instances to start the test operation. The corresponding caller method initializes the Runner class along with the number of iterations to be performed for each test case.

The Runner Class: The runner class includes one or multiple methods, which calls a bunch of methods of executor class, each of which contains required functionalities to call the test cases appropriately.

    • The Runner Base Class: One important issue with respect to the runner class is, we need to have a way to keep track to execution time for each run and finally we need to determine the average execution time. For this purpose, to perform required initialization and support common reporting feature of test cases, we considered a base class, which includes all tracking data to isolate individual test cases and reporting functionalities. We have used C# delegate to have a very structured and reusable object model regarding this common functionalities. The methods of the inherited class uses this features accordingly.

The Executor Class: The executor class contains the very basic codes with respect to a particular test case.

ClassDiagram

The Sample Codes

The  Program Class

class Program

    {

        static void Main(string[] args)

        {

            Output.WriteLine("Test starts: " + DateTime.Now.ToString());

            //----------------------------------------

            SampleRunner s1 = new SampleRunner(10);

            s1.RunBenchmarks();

            //----------------------------------------

            Output.WriteLine("Test ends: " + DateTime.Now.ToString());

            Console.ReadLine();

        }

    }

The Runner Base Class

public class SampleRunnerBase

    {

        protected delegate void DoWork(string text);

 

        long _Start;

        long _Stop;

        double _Total = 0;

        double _TotalSecs;

        double _TotalAvgSecs;

        int _Repeats;

        protected int _RepeatsToDo;

 

        public SampleRunnerBase(int repeats)

        {

            _RepeatsToDo = repeats;

        }

 

        private void Init()

        {

            _Total = 0;

            _TotalSecs = 0;

            _TotalAvgSecs = 0;

            _Repeats = _RepeatsToDo;

        }

 

        private void ReportResults()

        {

            _TotalSecs = _Total / 10000000;

            _TotalAvgSecs = _Total / 10000000 / _RepeatsToDo;

 

            Output.WriteLine("Avg: " + _TotalAvgSecs + " s");

        }

 

        protected void RunBenchmark(DoWork func, string text)

        {

            if (null != func)

            {

                Init();

                while (_Repeats-- > 0)

                {

                    _Start = DateTime.Now.Ticks;

                    func(text);

                    _Stop = DateTime.Now.Ticks;

                    _Total += _Stop - _Start;

                }

                ReportResults();

            }

        }

    }

The Runner Class

public sealed class SampleRunner : SampleRunnerBase

    {

        public SampleRunner(int repeats)

            : base(repeats)

        {

        }

 

        public void RunBenchmarks()

        {

 

            Output.WriteLine("Running Simple Sample Benchmark");

            Output.WriteLine("--------------------------------");

            RunSample1();

            RunSample2();

        }

 

        private void RunSample1()

        {

            Output.WriteLine("Running Sample 1");

            SampleExecutor runner = new SampleExecutor();

            RunBenchmark(new DoWork (runner.DoSample1), "");

        }

 

        private void RunSample2()

        {

            Output.WriteLine("Running Sample 2");

            SampleExecutor runner = new SampleExecutor();

            RunBenchmark(new DoWork(runner.DoSample2), "");

        }

 

    }

The Executor Class

public class SampleExecutor

    {

        public void DoSample1(string text)

        {

            //do something

        }

 

        public void DoSample2(string text)

        {

            //do something

        }

    }

 Download source code:

kick it on DotNetKicks.com

Posted on Thursday, November 22, 2007 4:32 PM Implementation , Architecture , Testing , .NET , Software Development | Back to top


Comments on this post: Creating a Performance Benchmark Framework for Your .NET Codes

# re: Creating a Performance Benchmark Framework for Your .NET Codes
Requesting Gravatar...
hi there,
i hope you can give me some guide here
What is the standard perforamance for ASP.Net ? is there benchmark for such thing ?

Left by sami on Dec 23, 2008 2:47 AM

Your comment:
 (will show your gravatar)


Copyright © Ashraf Alam | Powered by: GeeksWithBlogs.net | Join free