5 require 'testcontainer/rb.phar';
9 require 'RedUNIT/Base.php';
10 require 'RedUNIT/Base/Performance.php';
12 error_reporting( E_ALL );
14 //Load configuration file
15 if ( file_exists( 'config/test.ini' ) ) {
16 $ini = parse_ini_file( "config/test.ini", TRUE );
18 die( 'Cant find configuration file.' );
21 //Configure the databases
22 if ( isset( $ini['mysql'] ) ) {
23 $dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
25 R::addDatabase( 'mysql', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE );
27 R::selectDatabase( 'mysql' );
29 R::exec( ' SET GLOBAL sql_mode="" ' );
32 if ( isset( $ini['pgsql'] ) ) {
33 $dsn = "pgsql:host={$ini['pgsql']['host']};dbname={$ini['pgsql']['schema']}";
35 R::addDatabase( 'pgsql', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE );
38 if ( isset( $ini['sqlite'] ) ) {
39 R::addDatabase( 'sqlite', 'sqlite:' . $ini['sqlite']['file'], NULL, NULL, FALSE );
42 R::selectDatabase( 'sqlite' );
44 // Function to activate a driver
45 function activate_driver( $d )
47 R::selectDatabase( $d );
49 $test = new \RedUNIT\Base\Performance();
51 $drivers = $test->getTargetDrivers();
53 foreach ( $drivers as $driver ) {
55 if ( !isset( $ini[$driver] ) ) continue;
56 if ( !isset( $_SERVER['argv'][1])) die('Missing parameter. Usage: php runperf.php <testname> <TIMES> ');
58 $method = $_SERVER['argv'][1];
60 if ($method === 'setup') {
62 echo 'Setup...'.PHP_EOL;
71 if (isset($_SERVER['argv'][2])) {
72 $times = (int) $_SERVER['argv'][2];
75 echo "Performing test: $method with driver $driver ".PHP_EOL;
77 for ($j=0; $j<$times; $j++) {
79 $t1 = microtime( TRUE );
83 $t2 = microtime( TRUE );
94 echo PHP_EOL."AVG: $a, MAX: $mx, MIN: $mn, TOTAL: $s, TIMES: $times ".PHP_EOL;