<!DOCTYPE HTML><html>
<head>
<title>php/mysql benchmark</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
position: relative;
font-size: 12pt;
padding: 0;
margin: 0;
}
.banner {
width: 100%;
height: 52px;
background-color: lightgrey;
border-bottom: solid 2px grey;
text-align: center;
padding: 10px 0px;
}
.results {
width: 100%;
height: calc(100% - 74px);
}
div {
display: block;
}
.inl {
display: inline-block;
}
hr.half {
display: block;
position: relative;
width: 50%;
margin: 0 auto;
}
.frame {
display: inline-block;
margin: 10px 10px;
width: 300px;
margin-bottom: 0;
text-align: center;
border-bottom: solid 1px green;
}
.frame > object {
overflow-y: scroll;
height: 200px;
border: dashed 2px grey;
}
</style>
<link rel="stylesheet" type="text/css" media="all" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<body>
<div class="banner">
<div style="position: absolute; top:0;left:0;font-size: 9pt;">
Benchmark.php is Sourced by Odan <a href="https://github.com/odan/benchmark-php" target="_blank">on GitHub Here</a>
</div>
<div>
<div class="inl">
<b>Strategy:</b>
<select name="strategy">
<option value="single">Single Scan</option>
<option value="ramp">Multiple: Ramp Up</option>
<option value="bulk">Multiple: All at once</option>
</select>
</div>
<div class="inl">
<input type="button" name="do_op" value="Run" onclick="return handleExecute();" />
</div>
</div>
<hr class="half" />
<br />
<div>
<div class="inl">
[Avg. Hosting: <span id="avg_hosting" class="inl"></span>]
</div>
<div class="inl">
[Avg. Database: <span id="avg_database" class="inl"></span>]
</div>
</div>
</div>
<hr class="half" />
<div class="results">
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
window.monitor_frames=[];
window.php_stats=[];
window.mysql_stats=[];
window.intvl_monitor_frames = window.setInterval(threadCheckFrames, 1000);
window.isScanning=false;
window.hasBegunOperation=false;
window.isSpinningUp=false;
});
function handleExecute() {
if (window.hasBegunOperation) return;
window.hasBegunOperation=true;
$('.results').html('');
$('input[type=button][name=do_op]').prop('disabled','disabled').val("Running..");
$('#avg_hosting').html('<i class="fa fa-spinner fa-spin"></i>');
$('#avg_database').html('<i class="fa fa-spinner fa-spin"></i>');
var strategy = $('select[name=strategy]').val();
if (strategy === "single") run_single();
else if (strategy === "ramp") run_ramp();
else if (strategy === "bulk") run_bulk();
}
function get_embed(id) {
return '<div class="frame"><h4>Scan '+id+': [<span class="inl total"></span>]</h4><object id="'+id+'" type="text/html" data="/benchmark.php" width="100%" height="100%"></object></div>';
}
function get_embed_new_id() {
return 'frame-' + ($('.results > .frame').length + 1);
}
function run_single() {
var id = get_embed_new_id();
$('.results').append(get_embed(id));
window.monitor_frames.push({el: $('#'+id), done: false, id: id});
}
function run_ramp() {
window.isSpinningUp=true;
var base_delay=3*1000;
var current_delay=base_delay;
var cumulative_delay=0;
for (var f=0.0;f<0.9;f+=0.1) {
current_delay = base_delay - Math.pow(base_delay, f);
cumulative_delay += current_delay;
//console.log('delayed: '+current_delay +' , scheduled: '+cumulative_delay);
setTimeout(run_single, cumulative_delay);
}
setTimeout(function() {window.isSpinningUp=false;},cumulative_delay);
}
function run_bulk() {
for (var i=0;i<10;i++) {
run_single();
}
}
function threadCheckFrames() {
if (window.monitor_frames.length < 1 && !window.isSpinningUp) {
if (window.hasBegunOperation) {
$('input[type=button][name=do_op]').prop('disabled','').val("Run");
window.hasBegunOperation=false;
onAllFramesDone();
}
return;
}
if (window.isScanning) return;
window.isScanning=true;
cleanup_frames();
for (var i=0;i<window.monitor_frames.length;i++) {
var o = window.monitor_frames[i];
if (typeof(o.el[0].contentDocument)!=='undefined') {
var target_php = $('table tbody:nth-of-type(2) tr:last td:last', o.el[0].contentDocument.body);
var target_mysql = $('table tbody:nth-of-type(3) tr:last td:last', o.el[0].contentDocument.body);
var target_grand = $('table thead:last tr:last th:last', o.el[0].contentDocument.body);
if (target_php.length===1 && target_mysql.length===1 && target_grand.length===1) {
hasTargets=true;
window.monitor_frames[i].done=true;
var total_php = parseFloat(target_php.text());
var total_mysql = parseFloat(target_mysql.text());
var total = parseFloat(target_grand.text());
$('#'+o.id).parent().find('span.total').text(total+' sec');
window.php_stats.push(total_php);
window.mysql_stats.push(total_mysql);
}
}
}
window.isScanning=false;
}
function cleanup_frames() {
var new_av = [];
for (var i =0; i < window.monitor_frames.length; i++) {
if (!window.monitor_frames[i].done) {
new_av.push(window.monitor_frames[i]);
}
}
window.monitor_frames=new_av;
}
function onAllFramesDone() {
var avg_php=0.0;
var avg_mysql=0.0;
var total=0.0;
for(var i=0;i<php_stats.length;i++) {
total += php_stats[i];
}
avg_php = total / php_stats.length;
total=0.0;
for(var i=0;i<php_stats.length;i++) {
total += mysql_stats[i];
}
avg_mysql = total / mysql_stats.length;
window.php_stats=[];
window.mysql_stats=[];
$('#avg_hosting').html(avg_php.toFixed(2)+' sec');
$('#avg_database').html(avg_mysql.toFixed(2)+' sec');
}
</script>
</body>
</html>
P.s.
Frame access (javascript) was designed for chrome. Would need refactored to bypass the IE11 "permission denied" issue for window.frames[n].contentDocument , and Firefox probably doesn't like it either.
Here's my ramp up companion script for this..
P.s.
Frame access (javascript) was designed for chrome. Would need refactored to bypass the IE11 "permission denied" issue for window.frames[n].contentDocument , and Firefox probably doesn't like it either.