Coder Social home page Coder Social logo

benchmark-php's Introduction

benchmark-php

This is a PHP benchmark script to compare the runtime speed of PHP and MySQL. This project is inspired by www.php-benchmark-script.com (Alessandro Torrisi) an www.webdesign-informatik.de. In my point of view this script is more correct and comparable for different servers.

Screenshot

benchmark_v12

Setup

Upload benchmark.php and execute it:

HTML response:

http://www.example.com/benchmark.php

JSON response:

http://www.example.com/benchmark.php?json

MySQL Setup (optional)

  • Open benchmark.php
  • Edit this lines
$options['db.host'] = 'hostname';
$options['db.user'] = 'username';
$options['db.pw'] = 'password';
$options['db.name'] = 'database';
  • Upload and run the script

benchmark-php's People

Contributors

drexlma avatar janpio avatar jlzaratec avatar odan avatar solarisfire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

benchmark-php's Issues

Missing math result

Simple fix by adding <tr><td>Math</td><td>' . h($data['benchmark']['math']) . '</td></tr>

A benchmark isn't a benchmark w/out something to compare against

If users post their results, we'll all have something to compare against. Here is one from me to get it started.

image

Benchmark
math 1.652
string 2.239
loops 0.072
ifelse 0.133
connect 0.001
select_db 0.001
query_version 0.001
query_benchmark 10.707
total 14.803

'ENCODE' is deprecated and will be removed in a future release.

https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_decode

The DES_ENCRYPT() and DES_DECRYPT() functions are deprecated as of MySQL 5.7.6, will be removed in a future MySQL release, and should no longer be used. Consider using AES_ENCRYPT() and AES_DECRYPT() instead.

When I run SELECT BENCHMARK(1000000,ENCODE('hello',RAND())); in command line, it generates 65535 warnings. I think the warnings slows down the execution to 14 seconds. If I change to use AES_DECRYPT, the command returns in 2 seconds.

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper

Connection id:          4
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.7.25-0ubuntu0.16.04.2 (Ubuntu)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 25 min 2 sec

Threads: 1  Questions: 11  Slow queries: 0  Opens: 107  Flush tables: 1  Open tables: 26  Queries per second avg: 0.007
--------------

mysql> SELECT BENCHMARK(1000000,ENCODE('hello',RAND()));
+-------------------------------------------+
| BENCHMARK(1000000,ENCODE('hello',RAND())) |
+-------------------------------------------+
|                                         0 |
+-------------------------------------------+
1 row in set, 65535 warnings (14.95 sec)

mysql> SELECT BENCHMARK(1000000,AES_ENCRYPT('hello',RAND()));
+------------------------------------------------+
| BENCHMARK(1000000,AES_ENCRYPT('hello',RAND())) |
+------------------------------------------------+
|                                              0 |
+------------------------------------------------+
1 row in set (2.78 sec)

I think you may want to use AES_ENCRYPT.

[non-issue] just sharing code to run it and average results

Here's my ramp up companion script for this..

untitled

<!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.

return json

Hi, it would be great if the script responds with a json.

Like: benchmark.php?json

Thanks and a small suggestion

This is a super helpful script! Thank you. I'm adapting it slightly as a status monitor to allow my Kubernetes containers for a user research study to self-restart if certain test values are greater than what I'd like.

I noticed you are adding "secs" into the $result array in the benchmark tests functions. One minor suggestion would be to add on the string for the units in the print_benchmark_result() function. That way, the test results will be numeric and can be used for further processing. For example, I'll be using the values to determine the HTTP status code to return, as well as include the values as response headers.

RAND() is CPU-bound

Introduced in f88a374 the mysql query now uses RAND.

Doing that many calls to RAND is heavily CPU bound and generates at least 7 seconds on the benchmark test, which dwarfs the other metrics by far.

I feel that this i skewing the result quite a bit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.