cvs: php-benchmarks /benchcli/microtests test_array-gauss.php test_pcre.php test_recursion.php

From: Date: Mon, 22 Jun 2009 22:39:43 +0000
Subject: cvs: php-benchmarks /benchcli/microtests test_array-gauss.php test_pcre.php test_recursion.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-65125@lists.php.net to get a copy of this message
hjalle Mon Jun 22 22:39:43 2009 UTC Added files: /php-benchmarks/benchcli/microtests test_array-gauss.php test_pcre.php test_recursion.php Log: Restructuration of files (microtests directory added and microbenchs have been moved there) http://cvs.php.net/viewvc.cgi/php-benchmarks/benchcli/microtests/test_array-gauss.php?view=markup&rev=1.1 Index: php-benchmarks/benchcli/microtests/test_array-gauss.php +++ php-benchmarks/benchcli/microtests/test_array-gauss.php <?php error_reporting(E_ALL | E_STRICT); /** * Class that solves matrixes with the Gauss-Jordan elimination. */ class GaussJordan { var $eq,$nc,$s,$r,$grade,$solution; /** * Constructor for the Gauss-Jordan elimination * @param $eq int Number of rows * @param $nc int Number of columns * @param $s array The matrix to be eliminated * @param $r array The solution for the matrix * @return unknown_type */ function __construct($eq,$nc,$s,$r) { $this->eq = $eq; $this->nc = $nc; $this->s = $s; $this->r = $r; $solution = array(); } /** * Runs the Gauss-Jordan elimination process * * @return void */ function process() { for ($d = 0; ($d < $this->eq) && ($d < $this->nc); $d++) { if ($this->s[$d][$d]) { $tmp = 1/$this->s[$d][$d]; $this->multiplicate($d, $tmp); } for ($eqi = 0; $eqi < $this->eq; $eqi++) { if ($eqi == $d) continue; $tmp = -1 * $this->s[$eqi][$d]; $this->multsum($d, $tmp, $eqi); } } $ca = array(); $cv = array(); for ($eqi = 0; $eqi < $this->eq; $eqi++) { if ((min($this->s[$eqi]) != 0) || (max($this->s[$eqi]) != 0)) $cv[] = $eqi; if ((in_array($eqi, $cv)) || ($this->r[$eqi])) $ca[] = $eqi; } $c = count($ca) - count($cv); if ($c) $this->r = null; else { $this->grade = $this->nc - count($cv); } } /** * Multiplicates the row's values with the constant given. * * @param $row int The row to be multiplicated * @param $value int The value to multiplicate with * * @return void */ function multiplicate($row, $value) { for ($nci = 0; $nci < $this->nc; $nci++) { $this->s[$row][$nci] *= $value; } $this->r[$row] *= $value; } /** * Multiplicates and summarizes a row from one * to another with the given value. * * @param $origin int The row to use as reference * @param $value int The value to multiplicated with * @param $dest int The row to change * * @return void */ function multsum($origin, $value, $dest) { for ($nci = 0; $nci < $this->nc; $nci++) { $this->s[$dest][$nci] += ($this->s[$origin][$nci] * $value); } $this->r[$dest] += ($this->r[$origin] * $value); } } /* * This solves a seeded random matrix linear system * with the Gauss-Jordan algorithm. It's a NxN matrix * with N = 100. * */ function run($n) { $rows = $cols = $n; $seed = 20090522; srand($seed); for($i = 0; $i < $rows; $i++) { for($j = 0; $j < $cols; $j++) { $s[$i][$j] = rand(0,50); } $r[$i] = rand(200,1000); } $gauss = new GaussJordan($rows,$cols,$s,$r); $gauss->process(); } run(100); ?> http://cvs.php.net/viewvc.cgi/php-benchmarks/benchcli/microtests/test_pcre.php?view=markup&rev=1.1 Index: php-benchmarks/benchcli/microtests/test_pcre.php +++ php-benchmarks/benchcli/microtests/test_pcre.php <? // // emulates the parsing of sitemanager templates // define('SM_TAG_IDENTIFIER','SM'); // if you want something other than <SM> tags, change this define('SM_TAG_PREGEXP','/<\s*'.SM_TAG_IDENTIFIER.'\s(.+)\s*>/Ui'); define('SM_TAG_ATTR_PREGEXP','/(\w+)\s*=\s*[\"\'](.+)[\"\']/SUi'); function test() { $htmlTemplate = file("data/pcre-data.xml"); // for each line in the file... foreach ($htmlTemplate as $line) { // use this to determine what kind of tag we're dealing with $tagType = ''; $areaSub = ''; // check for standard SM tags if (preg_match_all(SM_TAG_PREGEXP,$line,$smTagMatch)) { // for each match we found on this line... for ($i=0; $i < sizeof($smTagMatch[1]); $i++) { // grab TYPE parameter $smParms = $smTagMatch[1][$i]; // parse the attributes // this screws with the type inference unset($attrs); // this should be friendlier // $attrs = array(); preg_match_all(SM_TAG_ATTR_PREGEXP,$smParms,$matchList); for ($x = 0; $x<count($matchList[1]); $x++) { $key = strtoupper($matchList[1][$x]); $attrs[$key] = $matchList[2][$x]; } } } // end of main tag block } } for ($i=0; $i<100; $i++) { test(); } ?> http://cvs.php.net/viewvc.cgi/php-benchmarks/benchcli/microtests/test_recursion.php?view=markup&rev=1.1 Index: php-benchmarks/benchcli/microtests/test_recursion.php +++ php-benchmarks/benchcli/microtests/test_recursion.php <?php /* $Id: test_recursion.php,v 1.1 2009/06/22 22:39:43 hjalle Exp $ http://www.bagley.org/~doug/shootout/ from Alexander Klimov */ function Ack($m, $n){ if($m == 0) return $n+1; if($n == 0) return Ack($m-1, 1); return Ack($m - 1, Ack($m, ($n - 1))); } $n = ($argc == 2) ? $argv[1] : 7; $r = Ack(3,$n); ?>

« previous php.qa (#65125) next »