Codeigniter Benchmarking Class Library


Codeigniter Benchmarking Class library – Codeigniter benchmarking class library provide various functions that are used for enables the time and memory consumption between two marked points. This library is always active and it is also automatically loaded by CodeIgniter. Here in this tutorial, we are going to explain how to use benchmarking class library.


Codeigniter Benchmarking Class library Example

This library is automatically loaded in codeIgniter.

Functions:-

There are two functions available in benchmarking class library. Now we will explain one by one with example.

  • 1. Total time execution
  • 2. Total memory consumption

1. Total time execution

Syntax of total time execution function is

Syntax of total time execution function is:-

$this->benchmark->mark('code_start');
// your coding
$this->benchmark->mark('code_end');
echo $this->benchmark->elapsed_time('code_start', 'code_end');

It has some classes:

  • 1. Mark a start point
  • 2. Mark a end point
  • 3. Run the “time consumption” function to view the results

This function calculates and displays the execution time of program.

EXAMPLE

Here is simple example of total time execution.

Total time execution in codeigniter example:-

//Controllers part
public function bench()
	{
		$this->load->view('library/bench_view');	
	}

// Views parts
<?php $this->benchmark->mark('code_start');
		$var = 20;
		if($var<30) { echo "$var is less than 30"; } else { echo "$var is greater than 30"; } $this->benchmark->mark('code_end');
        
?>

<?php echo $this->benchmark->elapsed_time();?>

The output will be like this –

Codeigniter Benchmarking Class library

2. Total memory consumption

Syntax of total memory consumption function is

Syntax of total memory consumption function is:-

$this->benchmark->mark('code_start');
// your coding
$this->benchmark->mark('code_end');
echo $this->benchmark->memory_usage();

It has also same properties.

This Function Calculates and display the memory consumption of program.

EXAMPLE

Here is simple example of total memory consumption.

Total memory consumption in codeigniter example:-

// Views parts
<?php $this->benchmark->mark('code_start');
		$var = 20;
		if($var<30) { echo "$var is less than 30"; } else { echo "$var is greater than 30"; } $this->benchmark->mark('code_end');
        
?>

<?php echo $this->benchmark->elapsed_time();?>
<?php echo $this->benchmark->memory_usage();?>

The output will be like this –

Codeigniter Benchmarking Class library

User Ans/Comments

📖 Read More


Advertisements