How to Benchmark PHP Code For Speed

In computer terminology, benchmark is the process of measuring the performance of computer resources, particularly the hardware, against any task performed by the computer.

Likewise testing the performance of software is called software benchmark. It basically gives a measure of CPU time and memory chunk, the software has consumed for its working. This is performed by running the computer programs within the software and thereby taking a collective measure of CPU and memory usage.

PHP Benchmark Performance Code

Software benchmark holds significant importance for real time software. Though it is done on a very intense ground with the help of very powerful benchmarking tools, but the programmers at their end can perform some benchmark using The Ubench PHP library available at:

https://github.com/devster/ubench

You just need to install this repository into your system and start benchmarking.

Installing via composer is preferably recommended.

Just need to add the following to your composer.json

Run composer and get it installed

The repository with the basic code as well as other dependencies will be automatically installed on your system under the folder “Ubench”.

Check This Also:

How to Benchmark PHP Code For Speed
Changing the Format of Date and Time in PHP
How to Create a Downloadable CSV File in PHP

Here is the Sample Code to use This Library

Write this code inside a php file and place it on the root path inside ubench directory.

sample.php

Output:

output will look like:

The value of x is 5000050001
CPU time taken 7ms
memory used 256.00Kb

Please notice to place the code, you need to test between $bench->start() and $bench->end() statements.

You can use other benchmark methods available in the ubench class files. Also many other tools are available on web to banchmark you PHP code.

Hope this article may give some benefit to you. Thanks.

Recommended Posts For You

About Manish Kumar

I am PHP web developer and blogger.

View all posts by Manish Kumar

Leave a Comment

Your email address will not be published. Required fields are marked *