|
@@ -3,12 +3,15 @@
|
|
|
class Benchmark {
|
|
|
var $pdo;
|
|
|
|
|
|
- public function setup_db()
|
|
|
+ public function setup_db($need_utf8 = false)
|
|
|
{
|
|
|
- $this->pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
|
|
|
- PDO::ATTR_PERSISTENT => true,
|
|
|
- PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
|
|
|
- ));
|
|
|
+ $attrs = array(PDO::ATTR_PERSISTENT => true);
|
|
|
+ // hhvm doesn't support charset=utf8 in the DSN yet
|
|
|
+ // See https://github.com/facebook/hhvm/issues/1309
|
|
|
+ if ($need_utf8) {
|
|
|
+ $attrs[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'utf8'";
|
|
|
+ }
|
|
|
+ $this->pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', $attrs);
|
|
|
}
|
|
|
|
|
|
public function bench_json()
|
|
@@ -25,7 +28,7 @@ class Benchmark {
|
|
|
|
|
|
public function bench_db()
|
|
|
{
|
|
|
- $this->setup_db();
|
|
|
+ $this->setup_db(false);
|
|
|
|
|
|
// Create an array with the response string.
|
|
|
$arr = array();
|
|
@@ -47,7 +50,7 @@ class Benchmark {
|
|
|
|
|
|
public function bench_queries($query_count=1)
|
|
|
{
|
|
|
- $this->setup_db();
|
|
|
+ $this->setup_db(false);
|
|
|
|
|
|
// Create an array with the response string.
|
|
|
$arr = array();
|
|
@@ -73,7 +76,7 @@ class Benchmark {
|
|
|
|
|
|
public function bench_updates($query_count)
|
|
|
{
|
|
|
- $this->setup_db();
|
|
|
+ $this->setup_db(false);
|
|
|
|
|
|
// Create an array with the response string.
|
|
|
$arr = array();
|
|
@@ -109,7 +112,7 @@ class Benchmark {
|
|
|
|
|
|
public function bench_fortunes()
|
|
|
{
|
|
|
- $this->setup_db();
|
|
|
+ $this->setup_db(true);
|
|
|
|
|
|
// Define query
|
|
|
$statement = $this->pdo->query( 'SELECT id, message FROM Fortune' );
|
|
@@ -133,9 +136,9 @@ class Benchmark {
|
|
|
<th>message</th>
|
|
|
</tr>
|
|
|
EOM;
|
|
|
- foreach ( $arr as $id => &$fortune ) {
|
|
|
+ foreach ( $arr as $id => $fortune ) {
|
|
|
echo '<tr>';
|
|
|
- echo '<td>'.htmlspecialchars($id, ENT_QUOTES, 'utf-8').'</td>';
|
|
|
+ echo '<td>'.$id.'</td>';
|
|
|
echo '<td>'.htmlspecialchars($fortune, ENT_QUOTES, 'utf-8').'</td>';
|
|
|
echo '</tr>';
|
|
|
}
|