Permalink
Browse files

Add simple and remove ol benmarking scripts.

  • Loading branch information...
1 parent 3db0cd2 commit 721d8fd79cee92aaff20f81a9b0ae62a6beca7ce @tricky tricky committed Jul 22, 2012
View
@@ -0,0 +1,10 @@
+benchmark: all
+ -@if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \
+ cd benchmark; \
+ BENCH_PHP_EXECUTABLE="$(PHP_EXECUTABLE)" \
+ BENCH_PHP_ARGS="-n -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS)" \
+ $(PHP_EXECUTABLE) -n ./run-bench.php; \
+ else \
+ echo "ERROR: Cannot run tests without CLI sapi."; \
+ fi
+
View
@@ -0,0 +1 @@
+*.txt
View
@@ -1,39 +0,0 @@
-<?php
-
-$data = array(
- 'euro2008' => array(
- 'title' => 'Euro 2008',
- 'description' => 'Pictures from UEFA EURO CUP 2008',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 1),
- array('width' => 600, 'height' => '400', 'id' => 2),
- array('width' => 300, 'height' => '200', 'id' => 3),
- array('width' => 300, 'height' => '200', 'id' => 4),
- )
- ),
-
- 'summer2008' => array(
- 'title' => 'Summer 2008',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 5),
- array('width' => 600, 'height' => '400', 'id' => 6),
- array('width' => 300, 'height' => '200', 'id' => 7),
- array('width' => 300, 'height' => '200', 'id' => 8),
- )
- ),
-
- 'summer2007' => array(
- 'title' => 'Summer 2007',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 9),
- array('width' => 600, 'height' => '400', 'id' => 10),
- array('width' => 300, 'height' => '200', 'id' => 11),
- array('width' => 300, 'height' => '200', 'id' => 12),
- array('width' => 300, 'height' => '200', 'id' => 13),
- )
- )
-);
-
-?>
View
@@ -1,78 +0,0 @@
-<?php
-
-$data = array(
- 'euro2008' => array(
- 'title' => 'Euro 2008',
- 'description' => 'Pictures from UEFA EURO CUP 2008',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 1),
- array('width' => 600, 'height' => '400', 'id' => 2),
- array('width' => 300, 'height' => '200', 'id' => 3),
- array('width' => 300, 'height' => '200', 'id' => 4),
- )
- ),
-
- 'summer2008' => array(
- 'title' => 'Summer 2008',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 5),
- array('width' => 600, 'height' => '400', 'id' => 6),
- array('width' => 300, 'height' => '200', 'id' => 7),
- array('width' => 300, 'height' => '200', 'id' => 8),
- )
- ),
-
- 'summer2007' => array(
- 'title' => 'Summer 2007',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 9),
- array('width' => 600, 'height' => '400', 'id' => 10),
- array('width' => 300, 'height' => '200', 'id' => 11),
- array('width' => 300, 'height' => '200', 'id' => 12),
- array('width' => 300, 'height' => '200', 'id' => 13),
- )
- ),
-
- 'summer2006' => array(
- 'title' => 'Summer 2006',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 14),
- array('width' => 600, 'height' => '400', 'id' => 15),
- array('width' => 300, 'height' => '200', 'id' => 16),
- array('width' => 300, 'height' => '200', 'id' => 17),
- array('width' => 300, 'height' => '200', 'id' => 18),
- array('width' => 300, 'height' => '200', 'id' => 19),
- )
- ),
-
- 'summer2005' => array(
- 'title' => 'Summer 2005',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 20),
- array('width' => 600, 'height' => '400', 'id' => 21),
- array('width' => 300, 'height' => '200', 'id' => 22),
- array('width' => 300, 'height' => '200', 'id' => 23),
- array('width' => 300, 'height' => '200', 'id' => 24),
- array('width' => 300, 'height' => '200', 'id' => 25),
- )
- ),
-
- 'summer2004' => array(
- 'title' => 'Summer 2004',
- 'description' => 'Summer \o/',
- 'pics' => array(
- array('width' => 600, 'height' => '400', 'id' => 26),
- array('width' => 600, 'height' => '400', 'id' => 27),
- array('width' => 300, 'height' => '200', 'id' => 28),
- array('width' => 300, 'height' => '200', 'id' => 29),
- array('width' => 300, 'height' => '200', 'id' => 30),
- array('width' => 300, 'height' => '200', 'id' => 31),
- )
- )
-);
-
-?>
View
@@ -0,0 +1,81 @@
+<?php
+
+class Bench {
+ private $name;
+ private $headerWritten = false;
+
+ private $started = false;
+
+ private $startTime;
+ private $stopTime;
+
+ private $startUsage;
+ private $stopUsage;
+
+ private $iterations;
+
+ public function __construct($name) {
+ $this->name = $name;
+ }
+
+ private function getResourceUsage() {
+ $rusage = getrusage();
+ $time = $rusage['ru_utime.tv_sec'] * 1000000 + $rusage['ru_utime.tv_usec'];
+ $time += $rusage['ru_stime.tv_sec'] * 1000000 + $rusage['ru_stime.tv_usec'];
+
+ return $time;
+ }
+
+ public function start() {
+ if ($this->started) {
+ throw new RuntimeException("Already started.");
+ }
+ $this->startTime = microtime(true);
+ $this->stopTime = $this->startTime;
+
+ $rusage = getrusage();
+
+ $this->startUsage = $this->getResourceUsage();
+ $this->stopUsage = $this->startUsage;
+ $this->started = true;
+ }
+
+ public function stop($i = 1) {
+ if (!$this->started) {
+ throw new RuntimeException("Not started.");
+ }
+
+ $this->stopTime = microtime(true);
+ $this->stopUsage = $this->getResourceUsage();
+
+ $this->iterations = (int)$i;
+ $this->started = false;
+ }
+
+ public function writeHeader() {
+ $header = implode("\t", array(
+ 'name', 'start time', 'iterations', 'duration', 'rusage',
+ ));
+ echo $header, "\n";
+ $this->headerWritten = true;
+ }
+
+ public function write() {
+ if ($this->started) {
+ $this->stop();
+ }
+
+ if (!$this->headerWritten) {
+ $this->writeHeader();
+ }
+
+ printf("%s\t%.6f\t%d\t%.8f\t%.6f\n",
+ $this->name,
+ $this->startTime,
+ $this->iterations,
+ $this->stopTime - $this->startTime,
+ $this->stopUsage - $this->startUsage);
+ }
+}
+
+
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,29 +0,0 @@
-<?php
-$data = array(
- 1 => array(
- 2 => array(3, 4, 5, 6),
- 3 => array(40, 50, 60, 70),
- 4 => array(500, 600, 700, 800),
- 2 => array(300000, 400000, 500000, 600000),
- 3 => array(400, 500, 600, 700),
- 4 => array(5000, 6000, 7000, 8000),
- ),
- 2 => array(
- 2 => array(3, 4, 5, 6),
- 3 => array(40, 50, 60, 70),
- 4 => array(500, 600, 700, 800),
- 2 => array(300000, 400000, 500000, 600000),
- 3 => array(400, 500, 600, 700),
- 4 => array(5000, 6000, 7000, 8000),
- ),
- 3 => array(
- 2 => array(3, 4, 5, 6),
- 3 => array(40, 50, 60, 70),
- 4 => array(500, 600, 700, 800),
- 2 => array(300000, 400000, 500000, 600000),
- 3 => array(400, 500, 600, 700),
- 4 => array(5000, 6000, 7000, 8000),
- )
-);
-
-?>
View
@@ -0,0 +1,48 @@
+<?php
+
+$dir = new DirectoryIterator('./');
+$stderr = fopen('php://stderr', 'w');
+
+$benchBaseName = getenv('BENCH_BASE_NAME');
+if ($benchBaseName === false) {
+ $benchBaseName = 'baseline';
+}
+
+foreach ($dir as $fileInfo) {
+ $fn = $fileInfo->getBasename();
+ $name = $fileInfo->getBasename('.b.php');
+
+ if (!preg_match('/\.b\.php$/', $fn)) {
+ continue;
+ }
+
+ $file = $fileInfo->openFile();
+ $file->setFlags(SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY);
+
+ $desc = $fn;
+ foreach ($file as $line) {
+ if (preg_match('/Description:\s*(.*)/', $line, $m)) {
+ $desc = trim($m[1]);
+ }
+ }
+
+ fwrite($stderr, str_pad($desc, 50, '.'));
+ $start = microtime(true);
+
+ $php = getenv('BENCH_PHP_EXECUTABLE');
+ if ($php === false) {
+ $php = 'php';
+ }
+
+ $args = getenv('BENCH_PHP_ARGS');
+ if ($args === false) {
+ $args = '';
+ }
+
+ $output = shell_exec($php . ' ' . $args . ' ' . $fileInfo->getFilename());
+
+ $stop = microtime(true);
+ fprintf($stderr, "DONE %.2fs\n", $stop - $start);
+
+ file_put_contents($benchBaseName . '-' . $name . '.txt', $output);
+}
View
@@ -1,3 +0,0 @@
-<?php
-$data = 42;
-?>
@@ -0,0 +1,30 @@
+<?php
+
+// Description: Serialize object array
+
+require_once 'bench.php';
+
+$b = new Bench('serialize-object-array');
+
+class Obj {
+ private $foo = 10;
+ public $bar = "test";
+ public $i;
+}
+
+$array = array();
+for ($i = 0; $i < 1000; $i++) {
+ $o = new Obj();
+ $o->i = $i;
+
+ $array[] = $o;
+}
+
+for ($i = 0; $i < 40; $i++) {
+ $b->start();
+ for ($j = 0; $j < 2000; $j++) {
+ $ser = igbinary_serialize($array);
+ }
+ $b->stop($j);
+ $b->write();
+}
@@ -0,0 +1,18 @@
+<?php
+
+// Description: Serialize scalar int
+
+require_once 'bench.php';
+
+$b = new Bench('serialize-scalar-int');
+
+$var = 1;
+
+for ($i = 0; $i < 40; $i++) {
+ $b->start();
+ for ($j = 0; $j < 3500000; $j++) {
+ $ser = igbinary_serialize($var);
+ }
+ $b->stop($j);
+ $b->write();
+}
@@ -0,0 +1,34 @@
+<?php
+
+// Description: Serialize scalar array
+
+require_once 'bench.php';
+
+$b = new Bench('serialize-scalar-array');
+
+$array = array();
+for ($i = 0; $i < 1000; $i++) {
+ switch ($i % 4) {
+ case 0:
+ $array[] = "da string " . $i;
+ break;
+ case 1:
+ $array[] = 1.31 * $i;
+ break;
+ case 2:
+ $array[] = rand(0, PHP_INT_MAX);
+ break;
+ case 3:
+ $array[] = (bool)($i & 1);
+ break;
+ }
+}
+
+for ($i = 0; $i < 40; $i++) {
+ $b->start();
+ for ($j = 0; $j < 12000; $j++) {
+ $ser = igbinary_serialize($array);
+ }
+ $b->stop($j);
+ $b->write();
+}
Oops, something went wrong.

0 comments on commit 721d8fd

Please sign in to comment.