<?php
// include class
include_once("class.LittleBenchmark.php");
// start global timer creating an instance
$obj = new LittleBenchmark;
// start partial timer
$obj->start();
for ($i=0; $i<50000; $i++) {
$hugeArray[$i] = mt_rand(1000,9999);
}
// stop partial timer
$obj->stop("huge array filled with random values");
unset($hugeArray); // free RAM
// start partial timer
$obj->start();
$hugeString='';
for ($i=0;$i<500000;$i++) {
$hugeString .= 'a';
}
$obj->stop("filled a string with 500,000 'a'");
unset($hugeString); // free RAM
// stop global timer and save last message
$obj->stopGlobalTimer("Below is the total time execution of this script.");
// output in JSON format
header("Content-type: application/json");
echo json_encode($obj->deltas);
// the output is valid JSON like the following:
/*
[
{
"EVENT": "GLOBAL TIMER STARTED",
"DELTA": "0 s",
"RAM_USAGE": "768 kb"
},
{
"EVENT": "huge array filled with random values",
"DELTA": "0.090872 s",
"RAM_USAGE": "8 mb"
},
{
"EVENT": "filled a string with 500,000 'a'",
"DELTA": "0.131289 s",
"RAM_USAGE": "1.75 mb"
},
{
"EVENT": "Below is the total time execution of this script.",
"DELTA": "0.226258 s",
"RAM_USAGE": "1.25 mb"
}
]
*/
?>
|