here is the all 3 files
index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>LF2PHPEasyBench</title>
<script>
google_ad_client = "pub-3197443558420570";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</HEAD>
<BODY>
<form action="bench.php" method="post">
<table border="0" cellpadding="3" cellspacing="1" width="500px" class="forumline">
<!-- GENERAL --------------------------------------->
<tr>
<th class="thHead" colspan="4" height="25" valign="middle">LF2PHPEasyBench</th>
</tr>
<!------------------Trial ---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Trial in Each time:</td>
<td class="row1" ><input type="text" name="trial" class="post" style="width: 100px" size="10" maxlength="6" value="1000" /></span></td>
</tr>
<!------------------Times ---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Test Times:</td>
<td class="row1" ><input type="text" name="times" class="post" style="width: 100px" size="10" maxlength="6" value="10" /></span></td>
</tr>
<!------------------dec ---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Decimal remain for the result:</td>
<td class="row1" ><input type="text" name="dec" class="post" style="width: 100px" size="10" maxlength="6" value="6" /></span></td>
</tr>
<!------------------Global function---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Code to exculte before any function:</td>
<td class="row1" > <textarea wrap='soft' name='global' rows=20 cols=25>$var = "Here put the PHP codes. opening tags are not needed.";</textarea></span></td>
</tr>
<!------------------function---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Code to exclute 1:</td>
<td class="row1" > <textarea wrap='soft' name='func_1' rows=20 cols=25>$var = "Here put the PHP codes. opening tags are not needed.";</textarea></span></td>
</tr>
<!------------------function---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Code to exclute 2:</td>
<td class="row1" > <textarea wrap='soft' name='func_2' rows=20 cols=25>$var = "Here put the PHP codes. opening tags are not needed.";</textarea></span></td>
</tr>
<!------------------function---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Code to exclute 3:</td>
<td class="row1" > <textarea wrap='soft' name='func_3' rows=20 cols=25>$var = "Here put the PHP codes. opening tags are not needed.";</textarea></span></td>
</tr>
<!------------------function---------------------------------------->
<tr>
<td class="row1" ><span class="gen">Code to exclute 4:</td>
<td class="row1" > <textarea wrap='soft' name='func_4' rows=20 cols=25>$var = "Here put the PHP codes. opening tags are not needed.";</textarea></span></td>
</tr>
<tr>
<td class="catBottom" colspan="2" align="center" height="28"><input type="submit" name="submit" value="submit" class="mainoption" /> <input type="reset" value="reset" name="reset" class="liteoption" /></td>
</tr>
</table>
</form><br>
<script type="text/javascript"><!--
google_ad_client = "pub-3197443558420570";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "000000";
google_color_bg = "F0F0F0";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br>
Made by <a href="http://mgccl.uni.cc">Mgccl</a>... who carez about copyright... use any part of my code as you want.
</BODY>
</HTML>
bench.php
<?php
include ('functions.php');
$i = 1;
while ($_POST['func_'.$i]){
$bench_post_func[$i] = stripslashes($_POST['func_'.$i]);
$i++;
}
$bench_post['global'] = stripslashes($_POST['global']);
$bench_post['trial'] = $_POST['trial'];
$bench_post['times'] = $_POST['times'];
$bench_post['dec'] = $_POST['dec'];
echo '<br>Global Stats<br>';
echo 'Trials for each test: '.$bench_post['trial'].'<br>';
echo 'Tests: '.$bench_post['times'].'<br>';
echo 'Decimals: '.$bench_post['dec'].'<br>';
echo 'Global Script: '.htmlentities($bench_post['global']).'<br><br>';
//A Freaken large while loop
$i = 0;
while ($i < count($bench_post_func)){
$bench_time = func_bench($bench_post_func, $bench_post['trial'], $bench_post['times'], $bench_post['dec'], $bench_post['global']);
$bench_totaltime[$i] = 0;
foreach ($bench_time[$i] as $bench_var) {
$bench_totaltime[$i] = $bench_totaltime[$i]+$bench_var;
}
$bench_averagetime[$i] = $bench_totaltime[$i]/$bench_post['times'];
echo '<br>Detail Stats<br>';
$i1 = $i + 1;
echo 'SCRIPT'.$i1.': <br> '.htmlentities($bench_post_func[$i1]).'<br>';
$bench_i = 1;
while ($bench_i <= $bench_post['times']){
echo 'Test No.'.$bench_i.': '.$bench_time[$i][$bench_i-1].'<br>';
$bench_i++;
}
$i++;
}
echo '<br>End RESULT FOR THESE SCRIPT in TOTAL, AVERAGE TIME PER TEST and AVERAGE TIME PER TRIAL<br><br>';
$i = 1;
$best['average']['var'] = 9999999;
while($i <= count($bench_post_func)){
echo 'Total Time For Script '.$i.': '.$bench_totaltime[$i-1].'<br>';
echo 'Average Time Per Test For Script '.$i.': '.$bench_averagetime[$i-1].'<br>';
echo 'Average Time Per Trial For Script '.$i.': '.$bench_averagetime[$i-1]/$bench_post['trial'].'<br>';
if ($bench_averagetime[$i-1]<$best['average']['var']) {
echo 'bench'.$bench_averagetime[$i].'<br>';
echo 'best'.$best['average']['var'].'<br>';
$best['average']['var'] = $bench_averagetime[$i-1];
$best['average']['n'] = $i;
}
$i++;
}
echo '<br>Best Average Time Per Test: <br>Script:'.$best['average']['n'].'<br>Time:'.$best['average']['var'].'<br>';
?>
functions.php
<?php
function func_bench($bench_function, $bench_trial=1000, $bench_times=10, $bench_dec=6, $bench_global='$bench_global = 0;'){
eval($bench_global);
$i = 0;
while($i<count($bench_function)) {
$bench_i = 0;
while ($bench_i < $bench_times){
$bench_n = 0;
$bench_timeparts = explode(' ',microtime());
$bench_starttime = $bench_timeparts[1].substr($bench_timeparts[0],1);
while($bench_n < $bench_trial) {
func_use($bench_function[$i]);
$bench_n++;
}
$bench_timeparts = explode(' ',microtime());
$bench_endtime = $bench_timeparts[1].substr($bench_timeparts[0],1);
$bench_time[$i][] = bcsub($bench_endtime,$bench_starttime,$bench_dec);
$bench_i++;
}
$i++;
}
return $bench_time;
}
function func_use($bench_function){
eval($bench_function);
}
?>
everything is find except.. it's always the 1st script runs the fastest(when all 4 input scripts are the same)
anyone know why?