// get value
$getval1 = f_BenchThisFct('f_test_global_getval');
$getval2 = f_BenchThisFct('f_test_globals_getval');
// get item
$item = array('item1');
$getitem1 = f_BenchThisFct('f_test_global_getitem', $item);
$getitem2 = f_BenchThisFct('f_test_globals_getitem', $item);
/* ---------------
   compare results
   --------------- */
f_EchoLine();
f_EchoLine('Compare results', 'u');
f_Compare("isset()=false with global", $isset1_f, 'isset()=false with $GLOBALS', $isset2_f);
f_Compare("isset()=true with global", $isset1_t, 'isset()=true with $GLOBALS', $isset2_t);
f_Compare("get the value with global", $getval1, 'get the value with $GLOBALS', $getval2);
f_Compare("get an item with global", $getitem1, 'get an item with $GLOBALS', $getitem2);
/* ------------
   end
   ------------ */
f_EchoLine();
f_EchoLine('End of tests', 'u');
$file = 'phpbench_global_vs_globals.php';
f_InfoEnd('<a href="http://tinybutstrong.svn.sourceforge.net/viewvc/tinybutstrong/trunk/benches/standalone/' . $file . '?view=markup">Source code of this bench</a>. Created for the <a href="http://www.tinybutstrong.com">TinyButStrong</a> project.', false);
exit;
/* --------------------------------------------
   FUNCTIONS AND CLASSES SPECIFIC TO THIS BENCH
   -------------------------------------------- */
function f_test_global_isset()
{
    global $MyVariable;
    return isset($MyVariable);
$b_ReverseCutStr = f_BenchThisFct('f_revsrch_ReverseCutStr', $prm, $nbr);
$b_ReverseFullStr = f_BenchThisFct('f_revsrch_ReverseFullStr', $prm, $nbr);
$b_ByChar_CharAsArray = f_BenchThisFct('f_revsrch_ByChar_CharAsArray', $prm, $nbr);
$b_ByChar_CharAsSubstr = f_BenchThisFct('f_revsrch_ByChar_CharAsSubstr', $prm, $nbr);
$b_ByChar_NoCharPrecheck = f_BenchThisFct('f_revsrch_ByChar_NoCharPrecheck', $prm, $nbr);
/* ---------------
   compare results
   --------------- */
f_EchoLine();
f_EchoLine('Compare results', 'u');
f_Compare("StrrposCut", $b_StrrposCut, "StrposUntilOffset", $b_StrposUntilOffset);
f_Compare("StrrposCut", $b_StrrposCut, "ReverseCutStr", $b_ReverseCutStr);
f_Compare("StrrposCut", $b_StrrposCut, "ReverseFullStr", $b_ReverseFullStr);
f_Compare("StrrposCut", $b_StrrposCut, "ByChar_CharAsArray", $b_ByChar_CharAsArray);
f_Compare("StrrposCut", $b_StrrposCut, "ByChar_CharAsSubstr", $b_ByChar_CharAsSubstr);
f_Compare("StrrposCut", $b_StrrposCut, "ByChar_NoCharPrecheck", $b_ByChar_NoCharPrecheck);
/* ------------
   end
   ------------ */
f_EchoLine();
f_EchoLine('End of tests', 'u');
$file = 'phpbench_reverse_str_search.php';
f_InfoEnd('<a href="http://tinybutstrong.svn.sourceforge.net/viewvc/tinybutstrong/trunk/benches/standalone/' . $file . '?view=markup">Source code of this bench</a>. Created for the <a href="http://www.tinybutstrong.com">TinyButStrong</a> project.', false);
exit;
/* --------------------------------------------
   FUNCTIONS AND CLASSES SPECIFIC TO THIS BENCH
   -------------------------------------------- */
function f_revsrch_StrrposCut($txt, $what, $offset)
{
    // Reverse search based on strrpos() by cuting the haystack.
    $p = strrpos(substr($txt, 0, $offset + 1), $what);
$prm = array(&$obj, $x);
$b0 = f_BenchThisFct('f_Nothing');
$b_Function = f_BenchThisFct('f_function_normal', $prm);
$b_NormalMethod = f_BenchThisFct('f_method_normal', $prm);
$b_StaticMethod = f_BenchThisFct('f_method_static', $prm);
$b_StaticMethodAsNormal = f_BenchThisFct('f_method_static_as_normal', $prm);
/* ---------------
   compare results
   --------------- */
f_EchoLine();
f_EchoLine('Compare results', 'u');
f_Compare("Function", $b_Function, "NormalMethod", $b_NormalMethod);
f_Compare("Function", $b_Function, "StaticMethod", $b_StaticMethod);
f_Compare("Function", $b_Function, "StaticMethodAsNormal", $b_StaticMethodAsNormal);
f_Compare("Method", $b_NormalMethod, "StaticMethod", $b_StaticMethod);
f_Compare("StaticMethodAsNormal", $b_StaticMethodAsNormal, "StaticMethod", $b_StaticMethod);
/* ------------
   end
   ------------ */
f_EchoLine();
f_EchoLine('End of tests', 'u');
$file = 'phpbench_function_vs_method.php';
f_InfoEnd('<a href="http://tinybutstrong.svn.sourceforge.net/viewvc/tinybutstrong/trunk/benches/standalone/' . $file . '?view=markup">Source code of this bench</a>. Created for the <a href="http://www.tinybutstrong.com">TinyButStrong</a> project.', false);
exit;
/* --------------------------------------------
   FUNCTIONS AND CLASSES SPECIFIC TO THIS BENCH
   -------------------------------------------- */
function f_function_normal(&$obj, $x)
{
    $y = f_function($x);
    return $y;
$x = f_test_create_array();
$b_read_array = f_BenchThisFct('f_test_read_array', array($x));
$x = f_test_create_object_byconv();
$b_read_object_std = f_BenchThisFct('f_test_read_object_any', array($x));
$x = f_test_create_object_bynew();
$b_read_object_spec = f_BenchThisFct('f_test_read_object_any', array($x));
/* ---------------
   compare results
   --------------- */
f_EchoLine();
f_EchoLine('Compare results', 'u');
f_Compare("create new instance of object", $b_create_object_std, "create array", $b_create_array);
f_Compare("create new instance of object", $b_create_object_spec, "create array converted in object", $b_create_object_std);
f_Compare("read array converted in object", $b_read_object_std, "read array", $b_read_array);
f_Compare("read new instance of object", $b_read_object_spec, "read array", $b_read_array);
f_Compare("read new instance of object", $b_read_object_spec, "read array converted in object", $b_read_object_std);
/* ------------
   end
   ------------ */
f_EchoLine();
f_EchoLine('End of tests', 'u');
$file = 'phpbench_array_vs_object.php';
f_InfoEnd('<a href="http://tinybutstrong.svn.sourceforge.net/viewvc/tinybutstrong/trunk/benches/standalone/' . $file . '?view=markup">Source code of this bench</a>. Created for the <a href="http://www.tinybutstrong.com">TinyButStrong</a> project.', false);
exit;
/* --------------------------------------------
   FUNCTIONS AND CLASSES SPECIFIC TO THIS BENCH
   -------------------------------------------- */
class clsTest
{
    var $name = 'James';
    var $subname = 'Dean';
f_EchoLine();
f_EchoLine('Speed measures', 'u');
$b0 = f_BenchThisFct('f_Nothing');
$prm_ok = array(basename(__FILE__));
$prm_err = array('this_file_do_not_exists.txt');
$b_fe_ok = f_BenchThisFct('f_test_file_exists', $prm_ok);
$b_fe_err = f_BenchThisFct('f_test_file_exists', $prm_err);
$b_of_ok = f_BenchThisFct('f_test_ofile', $prm_ok);
$b_of_err = f_BenchThisFct('f_test_ofile', $prm_err);
/* ---------------
   compare results
   --------------- */
f_EchoLine();
f_EchoLine('Compare results', 'u');
f_Compare("file_exists() with existing file", $b_fe_ok, "@fopen() with existing file", $b_of_ok);
f_Compare("file_exists() with non existing file", $b_fe_err, "@fopen() with non existing file", $b_of_err);
/* ------------
   end
   ------------ */
f_EchoLine();
f_EchoLine('End of tests', 'u');
$file = 'phpbench_fileexists_vs_fopen.php';
f_InfoEnd('<a href="http://tinybutstrong.svn.sourceforge.net/viewvc/tinybutstrong/trunk/benches/standalone/' . $file . '?view=markup">Source code of this bench</a>. Created for the <a href="http://www.tinybutstrong.com">TinyButStrong</a> project.', false);
exit;
/* --------------------------------------------
   FUNCTIONS AND CLASSES SPECIFIC TO THIS BENCH
   -------------------------------------------- */
function f_test_file_exists($file)
{
    if (file_exists($file)) {
        $x = fopen($file, 'r', true);