Introduction

Introduction – About Benchmarking_Benchmark

About Benchmarking_Benchmark

Benchmark is a simple framework that allows you time, profile and benchmark your PHP scripts and applications. Benchmark provides you with three classes to enable you to profile: Benchmark_Timer, Benchmark_Profiler and Benchmark_Iterate.

The package is very easy to use. We'll discuss each of the three classes in detail, but some concepts are common. You basically instantiate one of the classes, begin your script (or portion of code that you want to profile) and analyze the results afterward.

All the three classes have two modes of operation: automatic and manual. In the automatic mode of operation, the profiling is automatically started and stopped, and results displayed. In the manual mode, you are responsible for starting, stopping and displaying the results.

The automatic mode makes sense in cases where you want to quickly test a fixed portion of code like a script or a single function. The manual mode offers you more control, which means arbitrary portions of code can be profiled, and the results can be carefully analyzed before being displayed. In the automatic mode of operation, the results are always displayed; while in the manual mode you have the option of logging them or storing them in a database.

If you wish to operate a class in automatic mode, simply pass the TRUE parameter to its constructor. Instantiating a class without a parameter or with the FALSE parameter sets the mode of operation to manual for that class.

Which class to choose?

Benchmark_Timer is the most fundamental class in the package. It performs the simple function of recording the amount of time it takes for a fixed amount of code to execute.

Benchmark_Profiler behaves just like Benchmark_Timer with the exception that you are allowed to specify sections between the start and stop times, at which point the timing details are recorded. This provides the ability to nest timers and profile functions which are called multiple times.

Benchmark_Iterate is a class that runs a particular function several times over and records the amount of time it took for each iteration to execute.

    Поддержать сайт на родительском проекте КГБ