PHP Classes

File: benchmark_eval.php

Recommend this page to a friend!
  Classes of Jorge Castro   PHP Benchmarks   benchmark_eval.php   Download  
File: benchmark_eval.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Benchmarks
Evaluate the speed of PHP running different tasks
Author: By
Last change:
Date: 3 years ago
Size: 1,364 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
/** @noinspection AutoloadingIssuesInspection */


$numbers = range(0, 1000);

include
"Collection.php";

$instances=100000;

$exist=true;

function
ping($pong) {
    return
$pong;
}

// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
   
$r=ping("pong");
}
$t2=microtime(true);
$table['no_eval']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
    eval(
'$r=ping("pong");');
}
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['eval']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for(
$i=0;$i<$instances;$i++) {
   
$r=eval('return ping("pong");');
}
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['eval2']=$t2-$t1;


// **********************************************************************************
$t1=microtime(true);
$fnname='ping';
for(
$i=0;$i<$instances;$i++) {
   
$r=$fnname("pong");
}
$t2=microtime(true);
$table['dynamic_function']=$t2-$t1;

echo \
mapache_commons\Collection::generateTable($table);