PHP Classes

File: benchmark_env_vs_constant.php

Recommend this page to a friend!
  Classes of Jorge Castro  >  PHP Benchmarks  >  benchmark_env_vs_constant.php  >  Download  
File: benchmark_env_vs_constant.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: 1 year ago
Size: 828 bytes
 

Contents

Class file image Download
<?php

include "Collection.php";

$instances=50000;

// define constant

$t1=microtime(true);

define('COMPUTERNAME','HELLO WORLD');
for(
$i=0;$i<$instances;$i++) {
   
$a1=COMPUTERNAME;
}

$t2=microtime(true);

$result['DEFINE CONST']=$t2-$t1;

// define constant

$t1=microtime(true);

const
COMPUTERNAME2='HELLO WORLD';
for(
$i=0;$i<$instances;$i++) {
   
$a1=COMPUTERNAME2;
}
$t2=microtime(true);

$result['CONST']=$t2-$t1;


// env

$t1=microtime(true);

for(
$i=0;$i<$instances;$i++) {
   
$a1=getenv('computername');
}

$t2=microtime(true);

$result['env']=$t2-$t1;


// function

$t1=microtime(true);

function
returnValue() {
    return
'HELLO WORLD';
}

for(
$i=0;$i<$instances;$i++) {
   
$a1=returnValue();
}

$t2=microtime(true);

$result['function']=$t2-$t1;


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

For more information send a message to info at phpclasses dot org.