├── README.md ├── constants.php ├── index.php ├── time.php ├── dictionary.php ├── generic.txt ├── init.php ├── README ├── class.php ├── standard_calls.php ├── string.php ├── LICENSE └── db.php /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT. 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | -------------------------------------------------------------------------------- /constants.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /** 28 | * Constants used by mysql at authentification 29 | */ 30 | 31 | define('DB_USER', 'root'); 32 | define('DB_PASSWORD', 'root'); 33 | define('DB_NAME', 'pgo_train'); 34 | define('DB_HOST', 'localhost'); 35 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | require_once('constants.php'); 28 | include 'db.php'; 29 | include 'time.php'; 30 | include 'string.php'; 31 | include 'standard_calls.php'; 32 | include 'class.php'; 33 | include 'dictionary.php'; 34 | 35 | function getmicrotime() 36 | { 37 | $t = gettimeofday(); 38 | return ($t['sec'] + $t['usec'] / 1000000); 39 | } 40 | 41 | function start_test() 42 | { 43 | // ob_start(); 44 | return getmicrotime(); 45 | } 46 | 47 | function end_test($start, $name) 48 | { 49 | global $total; 50 | $end = getmicrotime(); 51 | // ob_end_clean(); 52 | $total += $end-$start; 53 | $num = number_format($end-$start,3); 54 | $pad = str_repeat(" ", 32-strlen($name)-strlen($num)); 55 | 56 | echo $name.$pad.$num."\n"; 57 | // ob_start(); 58 | return getmicrotime(); 59 | } 60 | 61 | function total() 62 | { 63 | global $total; 64 | $pad = str_repeat("-", 32); 65 | echo $pad."\n"; 66 | $num = number_format($total,3); 67 | $pad = str_repeat(" ", 32-strlen("Total")-strlen($num)); 68 | echo "Total".$pad.$num."\n"; 69 | } 70 | 71 | $functions = array(); 72 | hash_register_training($functions); 73 | mysql_register_training($functions); 74 | date_register_training($functions); 75 | string_register_training($functions); 76 | standard_register_training($functions); 77 | class_register_training($functions); 78 | $t0 = $t = start_test(); 79 | echo "\n--------------------------------\n"; 80 | echo "- Benchmark timing results -\n"; 81 | foreach ($functions as &$fname) { 82 | echo "--------------------------------\n"; 83 | for($i = 0 ; $i < 4; $i++) { 84 | $fname(); 85 | $t = end_test($t, ($i + 1) . "." . $fname); 86 | } 87 | 88 | } 89 | total($t0, "Total"); 90 | -------------------------------------------------------------------------------- /time.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /* Constants for scaling the number of runs; 28 | * Users can change these value for tuning execution weights 29 | */ 30 | define('STRTOTIME_IT', 120); /* # of strtotime() calls */ 31 | define('DATE_IT', 100); /* # of date() calls */ 32 | 33 | function date_register_training(& $functions) 34 | { 35 | /* if extension is missing goto next bench module */ 36 | if (!extension_loaded("date")) { 37 | echo " Date benchmark module not loaded: date extension is missing\n"; 38 | return -1; 39 | } 40 | 41 | echo "Date benchmark module loaded!\n"; 42 | $functions[] = "run_time"; 43 | } 44 | 45 | /** 46 | * Calls related to date/time from time.php 47 | */ 48 | function run_time() 49 | { 50 | run_strtotime(); 51 | run_date(); 52 | } 53 | 54 | /* *_IT can be found in constants.php. Modify the value 55 | there if you want to change time proportions*/ 56 | function run_strtotime() { 57 | $months = array("January", "February", "March", "April", "May", "June", 58 | "July", "August", "September", "October", "November", "December"); 59 | for ($i = 0; $i <= STRTOTIME_IT; $i++) { 60 | $num = rand(); 61 | $day = $num%28 + 1; 62 | $month = $num%12; 63 | $year = 1990 + $num%25; 64 | 65 | $date = $day . " " . $months[$month] . " " . $year; 66 | $rez = strtotime($date); 67 | $rez = strtotime("now"); 68 | $rez = strtotime("+10 days"); 69 | $rez = strtotime("-1 day"); 70 | $rez = strtotime("last Sunday"); 71 | $rez = strtotime("next Friday"); 72 | $rez = strtotime("+1 year 28 days 12 hours 13 seconds"); 73 | 74 | } 75 | 76 | } 77 | 78 | function run_date() { 79 | date_default_timezone_set('America/Los_Angeles'); 80 | for ($i = 0; $i <= DATE_IT; $i++) { 81 | $num = rand(); 82 | $day = $num%28 + 1; 83 | $month = $num%12; 84 | $year = $num%100; 85 | $f1 = $day . "." . $month . "." . $year; 86 | $f2 = $day . "-" . $month . "-" . $year; 87 | $f3 = $day . "/" . $month . "/" . $year; 88 | $d1 = date("jS F, Y", strtotime($f1)); 89 | $d2 = date("jS F, Y", strtotime($f2)); 90 | $d3 = date("jS F, Y", strtotime($f3)); 91 | } 92 | } 93 | ?> 94 | -------------------------------------------------------------------------------- /dictionary.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /* Constants for scaling the number of runs; 28 | * Users can change these value for tuning execution weights 29 | */ 30 | define('KEYS_SIZE', 50); /* number of keys pregenerated in keys.php */ 31 | define('DICTIONARY_IT', 300000); /* number of hash-map iterations */ 32 | define('ARRAY_KEYS_IT', 20000); /* # of array_keys() calls */ 33 | 34 | function hash_register_training(& $functions) 35 | { 36 | echo "Hash benchmark module loaded!\n"; 37 | $functions[] = "run_hash"; 38 | } 39 | 40 | function run_hash() 41 | { 42 | fill_dictionary(DICTIONARY_IT); 43 | } 44 | 45 | $KEYS = array("q0################", 46 | "q1#################", 47 | "q2##################", 48 | "q3###################", 49 | "q4####################", 50 | "q5#####################", 51 | "q6######################", 52 | "q7#######################", 53 | "q8########################", 54 | "q9#########################", 55 | "q10##########################", 56 | "q11###########################", 57 | "q12############################", 58 | "q13#############################", 59 | "q14##############################", 60 | "q15###############################", 61 | "q16################################", 62 | "q17#################################", 63 | "q18##################################", 64 | "q19###################################", 65 | "q20####################################", 66 | "q21#####################################", 67 | "q22######################################", 68 | "q23#######################################", 69 | "q24########################################", 70 | "q25#########################################", 71 | "q26##########################################", 72 | "q27###########################################", 73 | "q28############################################", 74 | "q29#############################################", 75 | "q30##############################################", 76 | "q31###############################################", 77 | "q32################", 78 | "q33#################", 79 | "q34##################", 80 | "q35###################", 81 | "q36####################", 82 | "q37#####################", 83 | "q38######################", 84 | "q39#######################", 85 | "q40########################", 86 | "q41#########################", 87 | "q42##########################", 88 | "q43###########################", 89 | "q44############################", 90 | "q45#############################", 91 | "q46##############################", 92 | "q47###############################", 93 | "q48################################", 94 | "q49#################################"); 95 | 96 | 97 | $dictionary = array(); 98 | $references = array(); 99 | 100 | function add_entry($name, $value) { 101 | if (isset($references[$name])) { 102 | $references[$name]++; 103 | } 104 | else { 105 | $references[$name] = 1; 106 | } 107 | $dictionary[$name] = $value; 108 | //count($dictionary); 109 | } 110 | 111 | function get_array_keys() { 112 | return array_keys($GLOBALS['dictionary']); 113 | } 114 | 115 | function get_array_values() { 116 | return array_values($GLOBALS['dictionary']); 117 | } 118 | 119 | 120 | function fill_dictionary($size) { 121 | 122 | if (!extension_loaded("hash")) { 123 | echo "Hash is missing!\n"; 124 | return -1; 125 | } 126 | 127 | $IT = $size / KEYS_SIZE; 128 | $KEYS = $GLOBALS["KEYS"]; 129 | for($j=0; $j < $IT; $j++) 130 | for ($i = 0; $i < KEYS_SIZE; $i++) { 131 | $name = 'KEYS'; 132 | add_entry($KEYS[$i], $i); 133 | $new = $$name[$i]; 134 | $new = null; 135 | } 136 | 137 | for ($i = 0; $i < ARRAY_KEYS_IT; $i++) { 138 | $keys = get_array_keys(); 139 | } 140 | for ($i = 0; $i < ARRAY_KEYS_IT; $i++) { 141 | $keys = get_array_values(); 142 | } 143 | 144 | } 145 | 146 | ?> 147 | -------------------------------------------------------------------------------- /generic.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * PHP PGO Training - to be used during Profile Guided Optimization builds. 3 | * 4 | * Copyright (C) 2016 Intel Corporation 5 | * 6 | * This program is free software and open source software; you can redistribute 7 | * it and/or modify it under the terms of the GNU General Public License as 8 | * published by the Free Software Foundation; either version 2 of the License, 9 | * or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 | * http://www.gnu.org/licenses/gpl.html 20 | * 21 | * Authors: 22 | * Gabriel Samoila 23 | * Bogdan Andone 24 | */ 25 | s 26 | This is a generic file; 27 | This is a generic file; 28 | This is a generic file; 29 | This is a generic file; 30 | Doesn't matter what text we have here!Doesn't matter what text we have here! 31 | Doesn't matter what text we have here! 32 | This is a generic file; 33 | This is a generic file; 34 | Doesn't matter what text we have here!Doesn't matter what text we have here! 35 | Doesn't matter what text we have here! 36 | This is a generic file; 37 | This is a generic file; 38 | Doesn't matter what text we have here!Doesn't matter what text we have here! 39 | Doesn't matter what text we have here! 40 | This is a generic file; 41 | This is a generic file; 42 | Doesn't matter what text we have here!Doesn't matter what text we have here! 43 | Doesn't matter what text we have here! 44 | 10.10.2010 45 | 23.12.2016 46 | This is a generic file; 47 | This is a generic file; 48 | This is a generic file; 49 | This is a generic file; 50 | Doesn't matter what text we have here!Doesn't matter what text we have here! 51 | Doesn't matter what text we have here! 52 | This is a generic file; 53 | This is a generic file; 54 | Doesn't matter what text we have here!Doesn't matter what text we have here! 55 | Doesn't matter what text we have here! 56 | This is a generic file; 57 | This is a generic file; 58 | Doesn't matter what text we have here!Doesn't matter what text we have here! 59 | Doesn't matter what text we have here! 60 | This is a generic file; 61 | This is a generic file; 62 | Doesn't matter what text we have here!Doesn't matter what text we have here! 63 | Doesn't matter what text we have here! 64 | 10.10.2010 65 | 23.12.2016This is a generic file; 66 | This is a generic file; 67 | This is a generic file; 68 | This is a generic file; 69 | Doesn't matter what text we have here!Doesn't matter what text we have here! 70 | Doesn't matter what text we have here! 71 | This is a generic file; 72 | This is a generic file; 73 | Doesn't matter what text we have here!Doesn't matter what text we have here! 74 | Doesn't matter what text we have here! 75 | This is a generic file; 76 | This is a generic file; 77 | Doesn't matter what text we have here!Doesn't matter what text we have here! 78 | Doesn't matter what text we have here! 79 | This is a generic file; 80 | This is a generic file; 81 | Doesn't matter what text we have here!Doesn't matter what text we have here! 82 | Doesn't matter what text we have here! 83 | 10.10.2010 84 | 23.12.2016This is a generic file; 85 | This is a generic file; 86 | This is a generic file; 87 | This is a generic file; 88 | Doesn't matter what text we have here!Doesn't matter what text we have here! 89 | Doesn't matter what text we have here! 90 | This is a generic file; 91 | This is a generic file; 92 | Doesn't matter what text we have here!Doesn't matter what text we have here! 93 | Doesn't matter what text we have here! 94 | This is a generic file; 95 | This is a generic file; 96 | Doesn't matter what text we have here!Doesn't matter what text we have here! 97 | Doesn't matter what text we have here! 98 | This is a generic file; 99 | This is a generic file; 100 | Doesn't matter what text we have here!Doesn't matter what text we have here! 101 | Doesn't matter what text we have here! 102 | 10.10.2010 103 | 23.12.2016This is a generic file; 104 | This is a generic file; 105 | This is a generic file; 106 | This is a generic file; 107 | Doesn't matter what text we have here!Doesn't matter what text we have here! 108 | Doesn't matter what text we have here! 109 | This is a generic file; 110 | This is a generic file; 111 | Doesn't matter what text we have here!Doesn't matter what text we have here! 112 | Doesn't matter what text we have here! 113 | This is a generic file; 114 | This is a generic file; 115 | Doesn't matter what text we have here!Doesn't matter what text we have here! 116 | Doesn't matter what text we have here! 117 | This is a generic file; 118 | This is a generic file; 119 | Doesn't matter what text we have here!Doesn't matter what text we have here! 120 | Doesn't matter what text we have here! 121 | 10.10.2010 122 | 23.12.2016 -------------------------------------------------------------------------------- /init.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | require_once('constants.php'); 28 | 29 | function printExistingDB() { 30 | echo "\n\t\t-=- Existing Databases -=-\n"; 31 | $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD); 32 | if ($conn->connect_error) { 33 | die("Connection failed: " . $conn->connect); 34 | } 35 | 36 | $command = "SHOW DATABASES"; 37 | $result = $conn->query($command); 38 | if ($result->num_rows > 0) { 39 | while ($row = $result->fetch_assoc()) { 40 | echo $row["Database"] . "\n"; 41 | } 42 | } else { 43 | echo "0 available databases\n"; 44 | } 45 | $conn->close(); 46 | } 47 | 48 | function insert_random_stuff($conn) { 49 | $yes_no = array("\"yes\"", "\"no\""); 50 | $names = array("\"WinnieThePooh\"" , "\"Mickey Mouse\"", "\"something\"", "\"random_name\"", "\"YetAnotherName\""); 51 | $values = array("\"value 1\"", "\"value 2\"", "\"limitless value\"", "\"minus value\"", "\"something\""); 52 | 53 | // for table 1 54 | for ($i=0; $i < 100; $i++) { 55 | $rand_1 = rand(0, $i); 56 | $rand_2 = rand(0, $i); 57 | $rand_3 = rand(0, $i); 58 | $command = "INSERT INTO table_one (col2, col3, col4) VALUES (" . $names[($i+$rand_1)%5] . "," . $values[($i+$rand_2)%5] . "," . $yes_no[($i+$rand_3)%2] .")"; 59 | if ($conn->query($command) == FALSE) { 60 | die("Error populating tables"); 61 | } 62 | } 63 | for ($i=0; $i < 15; $i++) { 64 | $rand_1 = rand(0, $i); 65 | $rand_2 = rand(0, $i); 66 | $rand_3 = rand(0, $i); 67 | $command = "INSERT INTO table_two (col2, col3) VALUES (" . $names[($i+$rand_1)%5] . "," . $values[($i+$rand_2)%5] . ")"; 68 | if ($conn->query($command) == FALSE) { 69 | die("Error populating tables"); 70 | } 71 | } 72 | for ($i=0; $i < 1000; $i++) { 73 | $rand_1 = rand(0, $i); 74 | $rand_2 = rand(0, $i); 75 | $rand_3 = rand(0, $i); 76 | $command = "INSERT INTO table_three (col2, col3) VALUES (" . $names[($i+$rand_1)%5] . "," . $values[($i+$rand_2)%5] . ")"; 77 | if ($conn->query($command) == FALSE) { 78 | die("Error populating tables"); 79 | } 80 | } 81 | } 82 | 83 | function initDB() { 84 | 85 | echo "\n\t\t-=- init Database(s) -=-\n"; 86 | // Connect to mysql 87 | $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD); 88 | if ($conn->connect_error) { 89 | die("Connection failed: " . $conn->connect); 90 | } 91 | 92 | if ($conn->select_db(DB_NAME)) { 93 | $command = "DROP DATABASE " . DB_NAME ; 94 | if ($conn->query($command) == TRUE) { 95 | echo "Database " . DB_NAME . " succesfully dropped\n"; 96 | } else { 97 | echo "Error dropping database " . DB_NAME . ": " . $conn->error . "\n"; 98 | } 99 | } 100 | 101 | // Create database 102 | $command = "CREATE DATABASE " . DB_NAME; 103 | if ($conn->query($command) == TRUE) { 104 | echo "Database " . DB_NAME . " created succesfully\n"; 105 | } else { 106 | echo "Error creating database: " . DB_NAME . $conn->error . "\n"; 107 | } 108 | $command = "USE " . DB_NAME; 109 | 110 | $conn->query($command); 111 | /* drop tables if exitst */ 112 | $conn->query("DROP TABLE table_one"); 113 | $conn->query("DROP TABLE table_two"); 114 | $conn->query("DROP TABLE table_three"); 115 | /* create required tables */ 116 | $command = " 117 | CREATE TABLE IF NOT EXISTS table_one ( 118 | col1 bigint(5) NOT NULL AUTO_INCREMENT, 119 | col2 varchar(50) DEFAULT NULL, 120 | install_date DATE DEFAULT NULL, 121 | col3 varchar(64) DEFAULT NULL, 122 | col4 varchar(250) DEFAULT NULL, 123 | PRIMARY KEY(col1) 124 | )"; 125 | $conn->query($command); 126 | 127 | $command = " 128 | CREATE TABLE IF NOT EXISTS table_two ( 129 | col1 bigint(5) NOT NULL AUTO_INCREMENT, 130 | col2 varchar(50) DEFAULT NULL, 131 | col3 varchar(64) DEFAULT NULL, 132 | PRIMARY KEY(col1) 133 | )"; 134 | 135 | $conn->query($command); 136 | $command = " 137 | CREATE TABLE IF NOT EXISTS table_three ( 138 | col1 bigint(5) NOT NULL AUTO_INCREMENT, 139 | col2 varchar(50) DEFAULT NULL, 140 | col3 varchar(64) DEFAULT NULL, 141 | PRIMARY KEY(col1) 142 | )"; 143 | if ($conn->query($command) == TRUE) { 144 | echo "Created tables in " . DB_NAME . "\n"; 145 | } else { 146 | echo "Error creating tables in : " . DB_NAME . $conn->error . "\n"; 147 | } 148 | insert_random_stuff($conn); 149 | $conn->close(); 150 | } 151 | 152 | initDB(); 153 | printExistingDB(); 154 | ?> 155 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | CONTENTS OF THIS FILE 2 | --------------------- 3 | * Introduction 4 | * Prerequisites 5 | * Installation 6 | * Usage 7 | * Modules 8 | - Hash Module 9 | - Database Module 10 | - Standard Module 11 | - String Module 12 | - Time Module 13 | 14 | 15 | INTRODUCTION 16 | ----------- 17 | PHP PGO Training scripts were created as a representative execution 18 | pattern for real life PHP applications like WordPress, MediaWiki or Drupal. 19 | When executed during the training phase of a PGO (Profile Guided 20 | Optimization) build process these scripts will provide similar statistics 21 | as if the PGO training was performed with the real life application. 22 | The advantage of using these scripts instead of real applications 23 | is that they are easily portable and they don't need complex installation 24 | steps as for real live use cases. The only one dependency is on MySQL. In 25 | consequencei, the scripts can be easily integrated directly in source 26 | ditribution packages of Zend PHP or HHVM in order to offer transparent 27 | support for PGO builds. 28 | The current version tries to reproduce Wordpress execution behavior. 29 | Tested for PGO builds of PHP7 using GCC 5.0, it delivered half of the 30 | performance speedups obtained during PGO builds trained with the real 31 | applications. It was tested for: 32 | - Wordpress 4.2.2: ~3.5% speedup 33 | - Drupal 7.36: ~2% speedup 34 | - MediaWiki 1.23.9: ~1.5% speedup 35 | 36 | 37 | PREREQUISITES 38 | ------------- 39 | PHP PGO Training Scripts assume you want to build optimized PHP/HHVM 40 | binaries from scratch following the Profile Guided Optimization build process. 41 | Here is the list of prerequisites: 42 | - prerequisites of building PHP7/HHVM binaries from scratch (see build 43 | documentation on PHP7/HHVM for more details) 44 | - a C/C++ compiler supporting profile guided optimized builds. We used GCC 5.0 45 | - a MySQL server installed, if database operations are targeted for training 46 | 47 | 48 | INSTALLATION 49 | ------------ 50 | Copying the PHP PGO training scripts in a folder is enough if you are 51 | not interested in training database accesses. Otherwise, you shall also: 52 | 1. Configure access credentials to MySQL server. Edit 'constants.php' file 53 | and document the following fields: 54 | - DB_USER: name of a valid database user 55 | - DB_PASSWORD: password of the database user 56 | - DB_HOST: the datatabse host to be used for training 57 | - DB_NAME: name of the database to be created and used for training 58 | 2. Install the training database on the MySQL server; you can rerun this 59 | script whenever you want to bring the database to it's initial state: 60 | $ php /path/to/php_pgo_training_scripts/init.php 61 | 62 | USAGE: 63 | ------ 64 | The entry point for executing the entire bunch of scripts is 'index.php'. 65 | For reproducing closely a real live execution scenario where we assume a HTTP 66 | server is loading and compiling once the PHP scripts and executes them many 67 | times, we need to reduce the weight of the compilation phase during the training 68 | execution. The following command was good enough for this purpose: 69 | $ php-cgi -T100 /path/to/php_pgo_training_scripts/index.php 70 | Of course, we assumed 'opcache' enabled in case of PHP7. 71 | 72 | The following steps are an example on how to perform a PGO build on 73 | PHP7 using these training scripts: 74 | $ cd /path/to/php-src 75 | $ ./configure ... # see PHP installation details for more info 76 | $ make prof-gen # builds instrumented binaries for execution statistcs 77 | # gathering 78 | $ ./sapi/cgi/php-cgi -T100 /path/to/php_pgo_training_scripts/index.php 79 | $ make prof-clean # cleans up the project but preserves 80 | # gathered statistics 81 | $ make prof-use # rebuilds binaries based on gathered statistics 82 | $ sudo make install 83 | 84 | For executiong all training scenarios the following PHP extensions 85 | shall be enabled in PHP during the initial configuration phase: 86 | - standard 87 | - mysqli 88 | - mbstring 89 | - pcre 90 | - date 91 | If one of the above extensions is not found at runtime the scripts will 92 | skip the associated trainings and will issue a warning message. 93 | 94 | 95 | Modules 96 | ------- 97 | 98 | +--------+ +----------+ +----------+ +----------+ +------+ 99 | + HASH +<--->+ DATABASE +<--->+ STANDARD +<--->+ STRING +<--->+ TIME + 100 | +--------+ +----------+ +----------+ +----------+ +------+   101 | 102 | At top level of each module you can find constants that controls 103 | the number of iterations for each basic training. These constants were 104 | empirically set based on observations on Wordpress execution pattern. 105 | If you need to change the relative weight between different kind of loads, 106 | they can be adjusted depending on needs. 107 | 108 | 1. Hash Module(dictionary.php): A set of 50 keys is used to store and increment 109 | values in an array. 110 | 111 | 2. Database Module(db.php): A database connection is created and a series of 112 | queries are done(from simple select * from table to updates and select 113 | with joins). The database is created using init.php and its content is 114 | some random generated data. The tables format is similar to WordPress 115 | tables format. 116 | 117 | 3. Standard Module(standard_calls.php): The following functions are called 118 | inside this module: 119 | error_reporting(E_ERROR | E_WARNING | E_PARSE); 120 | array_walk($test_array, 'do_nothing'); 121 | krsort($test_array); 122 | ksort($test_array); 123 | parse_str($var1); 124 | end($test_array); 125 | reset($test_array); 126 | array_shift($test_array); 127 | array_pop($test_array); 128 | array_diff($test_array1, $test_array); 129 | extract($test_array, EXTR_PREFIX_SAME, "wddx"); 130 | version_compare(phpversion(), '5.5', '>='); 131 | fread($file,"1024"); 132 | fclose($file); 133 | 134 | 4. String Module(string.php): All common string operations are done on an 135 | array containing 6 strings: 136 | preg_replace 137 | preg_replace_callback 138 | str_replace 139 | str_split 140 | md5 141 | trim 142 | implode 143 | mb_check_encoding 144 | 145 | 5. Time Module(time.php): Calls strtotime and date using different formats. 146 | 147 | -------------------------------------------------------------------------------- /class.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /* Constants for scaling the number of runs; 28 | * Users can change these value for tuning execution weights 29 | */ 30 | define('CLASS_STUDENT_IT', 100); /* # of classes created */ 31 | 32 | function class_register_training(& $functions) 33 | { 34 | echo "Class benchmark module loaded!\n"; 35 | $functions[] = "run_class"; 36 | } 37 | 38 | function run_class() { 39 | run_create_classes(); 40 | } 41 | 42 | /** 43 | * This php file constains classes that simulates WP classes. 44 | */ 45 | class Student { 46 | 47 | var $valid = false; 48 | var $string_var = 'This is Student class'; 49 | static $num_instances = 0; 50 | var $num_var = 0; 51 | var $float_var = 3.1415; 52 | var $grades = array(); 53 | var $grades_string_array = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'); 54 | var $float_array = array(1.1, 2.2, 3.3, 3.14, 2.73); 55 | var $bool_array = array(true, false, true, true, false); 56 | var $storage = array(); 57 | var $end = false; 58 | protected $name; 59 | protected $date; 60 | protected $annual_grade; 61 | private $faculty; 62 | private $university; 63 | public $available_methods = array("set_float", "get_float", "set_personal_info", 64 | "set_fac", "get_fac", "print", "set_grades", 65 | "get_grades", "get_grade", "make_unusable", "to_string"); 66 | 67 | function Student() { 68 | $this->valid = true; 69 | $this->annual_grade = 0.0; 70 | Student::$num_instances += 1; 71 | } 72 | 73 | function set_float($var) { 74 | $this->float_var = $var; 75 | } 76 | 77 | function get_float() { 78 | return $this->float_var; 79 | } 80 | 81 | function set_personal_info($n, $d, $g) { 82 | $this->name = $n; 83 | $this->date = $d; 84 | $this->annual_grade = $g; 85 | } 86 | function get_personal_info() { 87 | $rez = (string)$this->name . " " . (string)$this->date . " " . (string) $this->annual_grade; 88 | return $rez; 89 | } 90 | 91 | function set_fac($f, $u) { 92 | $this->faculty = $f; 93 | $this->university = $u; 94 | } 95 | 96 | function get_fac() { 97 | $rez = (string)$this->faculty . " " . (string)$this->university; 98 | return $rez; 99 | } 100 | function print() { 101 | echo Student::$num_instances; 102 | } 103 | 104 | function set_grades($g_array) { 105 | $this->grades = $g_array; 106 | $len = sizeof($this->grades); 107 | for ($i=0; $i<$len; $i++) { 108 | $this->annual_grade += $this->grades[$i]; 109 | } 110 | $this->annual_grade /= $len; 111 | } 112 | 113 | function get_grades() { 114 | return $this->grades; 115 | } 116 | 117 | function get_grade() { 118 | return $this->annual_grade; 119 | } 120 | 121 | function make_unusable() { 122 | $this->valid = false; 123 | } 124 | function to_string() { 125 | $rez = "Personal info: " . $this->get_personal_info() . "\n\t" . $this->get_fac(); 126 | $rez .= "\nGrades: \n"; 127 | $grades_array = $this->get_grades(); 128 | $len = sizeof($grades_array); 129 | for ($i =0; $i < $len ; $i++) { 130 | $rez .= "\t" . $grades_array[$i] . "\n"; 131 | } 132 | $rez .="Annual grade: " . $this->annual_grade . "\n"; 133 | return $rez; 134 | } 135 | 136 | function get_available_methods() { 137 | return $this->available_methods; 138 | } 139 | 140 | } 141 | 142 | class LastYearStudent extends Student { 143 | var $group; 144 | function set_group($g) { 145 | $this->group = $g; 146 | } 147 | } 148 | 149 | class Faculty { 150 | var $name; 151 | var $city; 152 | var $country; 153 | var $university_name; 154 | var $students = array(); 155 | 156 | function Faculty($n, $cty, $ctry, $uname) { 157 | $this->name = $n; 158 | $this->city = $cty; 159 | $this->country = $ctry; 160 | $this->university_name = $uname; 161 | } 162 | 163 | function add_student($stud) { 164 | array_push($this->students, $stud); 165 | } 166 | 167 | } 168 | function startsWith($haystack, $needle) 169 | { 170 | $length = strlen($needle); 171 | return (substr($haystack, 0, $length) === $needle); 172 | } 173 | 174 | /** 175 | * Students are created here and Student class methods 176 | * are called. 177 | */ 178 | function create_student() { 179 | $stud = new Student(); 180 | 181 | /* some method call by name */ 182 | $name = "James J Jordan"; 183 | $date = "10-09-1993"; 184 | $grade = 0.0; 185 | call_user_func(array($stud, "set_personal_info"), $name, $date, $grade); 186 | 187 | $fname = "Some Faculty of Computer Science"; 188 | $uname = "University of Humans and/or Machines"; 189 | call_user_func(array($stud, "set_fac"), $fname, $uname); 190 | 191 | /* some clasic method call */ 192 | $grades = array(10,9,7,9); 193 | $stud->set_grades($grades); 194 | 195 | $description = $stud->to_string(); 196 | $methods = $stud->get_available_methods(); 197 | for ($i = 0; $i < sizeof($methods); $i++) { 198 | /* call all student getters */ 199 | if (startsWith($methods[$i], "get")) { 200 | $rval = call_user_func(array($stud, $methods[$i])); 201 | } 202 | } 203 | return $stud; 204 | } 205 | 206 | function create_last_year_student() { 207 | $stud = new LastYearStudent(); 208 | 209 | /* some method call by name */ 210 | $name = "Smithy Jones"; 211 | $date = "10-09-1990"; 212 | $grade = 0.0; 213 | call_user_func(array($stud, "set_personal_info"), $name, $date, $grade); 214 | 215 | $fname = "Some Faculty of Computer Science"; 216 | $uname = "University of Humans and/or Machines"; 217 | call_user_func(array($stud, "set_fac"), $fname, $uname); 218 | 219 | /* some clasic method call */ 220 | $grades = array(10,9, 10,9); 221 | $stud->set_grades($grades); 222 | 223 | $description = $stud->to_string(); 224 | $methods = $stud->get_available_methods(); 225 | for ($i = 0; $i < sizeof($methods); $i++) { 226 | /* call all student getters */ 227 | if (startsWith($methods[$i], "get")) { 228 | $rval = call_user_func(array($stud, $methods[$i])); 229 | } 230 | } 231 | return $stud; 232 | } 233 | 234 | /** 235 | * This function creates CLASS_STUDENT_IT students and 236 | * adds them to faculty class 237 | */ 238 | function run_create_classes() { 239 | $fac = new Faculty("Some Faculty of Computer Science", "GenericCityName", "GenericCountryName", "UNIVERSITY"); 240 | for($i=0; $i < CLASS_STUDENT_IT; $i++) { 241 | $s = create_student(); 242 | $fac->add_student($s); 243 | } 244 | $s = create_last_year_student(); 245 | $fac->add_student($s); 246 | $s = create_last_year_student(); 247 | $fac->add_student($s); 248 | $s = create_last_year_student(); 249 | $fac->add_student($s); 250 | } 251 | 252 | ?> 253 | -------------------------------------------------------------------------------- /standard_calls.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /* Constants for scaling the number of runs; 28 | * Users can change these value for tuning execution weights 29 | */ 30 | define('STANDARD_CALL_IT', 10000); /* # of different standard calls */ 31 | define('INI_SET_IT',100); /* # of set_it() calls*/ 32 | define('FUNC_EXISTS_IT',1000); /* # of function_exists() calls */ 33 | define('FILE_OPS_IT', 10); /* # of fopen(), fread(), fclose() calls */ 34 | define('FILE_EXISTS_IT', 500); /* # of file_exists() calls */ 35 | define('ARRAY_MAP_IT', 4200); /* # of array_map() calls */ 36 | define('ARRAY_MERGE_IT', 12500); /* # of array_merge() calls */ 37 | define('PREG_MATCH_IT', 10000); /* # of preg_match() calls */ 38 | define('PARSE_URL_IT', 1000); /* # of parse_url() calls */ 39 | define('VERSION_COMPARE_IT', 1200); /* # of version_compare() calls */ 40 | 41 | /* entry point for this module will be added into 42 | array if required extensions exists */ 43 | function standard_register_training(& $functions) 44 | { 45 | if (!extension_loaded("standard")) { 46 | echo " Standard benchmark module not loaded: standard extension is missing\n"; 47 | return -1; 48 | } 49 | 50 | echo "Standard benchmark module loaded!\n"; 51 | $functions[] = "run_standard"; 52 | } 53 | 54 | /** Standard php calls. Use variables defined below to 55 | * control the proportions of different standard calls. 56 | */ 57 | function run_standard() { 58 | $STANDARD_CALL_PARAM = STANDARD_CALL_IT; 59 | $INI_SET_PARAM = INI_SET_IT; 60 | $FUNC_EXISTS_PARAM = FUNC_EXISTS_IT; 61 | $FILE_OPS_PARAM = FILE_OPS_IT; 62 | $FILE_EXISTS_PARAM = FILE_EXISTS_IT; 63 | $ARRAY_MAP_PARAM = ARRAY_MAP_IT; 64 | $VERSION_COMPARE_PARAM = VERSION_COMPARE_IT; 65 | $ARRAY_MERGE_PARAM = ARRAY_MERGE_IT; 66 | $PREG_MATCH_PARAM = PREG_MATCH_IT; 67 | $PARSE_URL_PARAM = PARSE_URL_IT; 68 | 69 | 70 | run_standard_calls($STANDARD_CALL_PARAM); 71 | run_array_map($ARRAY_MAP_PARAM); 72 | run_array_merge($ARRAY_MERGE_PARAM); 73 | run_preg_match($PREG_MATCH_PARAM); 74 | run_parse_url($PARSE_URL_PARAM); 75 | run_version_compare($VERSION_COMPARE_PARAM); 76 | run_file_exists($FILE_EXISTS_PARAM); 77 | run_file_operations($FILE_OPS_PARAM); 78 | run_ini_set($INI_SET_PARAM); 79 | } 80 | 81 | $var_g = "The Intel Core microarchitecture (previously known as the Next-Generation Micro-Architecture)";// is a multi-core processor microarchitecture unveiled by Intel in Q1 2006. It is based on the Yonah processor design and can be considered an iteration of the P6 microarchitecture, introduced in 1995 with Pentium Pro. The high power consumption and heat intensity, the resulting inability to effectively increase clock speed, and other shortcomings such as the inefficient pipeline were the primary reasons for which Intel abandoned the NetBurst microarchitecture and switched to completely different architectural design, delivering high efficiency through a small pipeline rather than high clock speeds. The Core microarchitecture never reached the clock speeds of the Netburst microarchitecture, even after moving to 45 nm lithography."; 82 | $var1_g = "The = Intel = Core"; 83 | $some_url_g = "http://CentOs:password@intel:8080/go?arg=link#text"; 84 | $test_array1_g = preg_split("/[\s,]+/", $var1_g); 85 | $test_array_g = preg_split("/[\s,]+/", $var_g); 86 | 87 | 88 | function do_nothing(&$item, $key) { 89 | // nothing at all 90 | } 91 | function replace($word) { 92 | return "this->" . $word; 93 | } 94 | 95 | function run_standard_calls($STANDARD_CALL_IT) { 96 | $var = "The Intel Core microarchitecture (previously known as the Next-Generation Micro-Architecture)";// is a multi-core processor microarchitecture unveiled by Intel in Q1 2006. It is based on the Yonah processor design and can be considered an iteration of the P6 microarchitecture, introduced in 1995 with Pentium Pro. The high power consumption and heat intensity, the resulting inability to effectively increase clock speed, and other shortcomings such as the inefficient pipeline were the primary reasons for which Intel abandoned the NetBurst microarchitecture and switched to completely different architectural design, delivering high efficiency through a small pipeline rather than high clock speeds. The Core microarchitecture never reached the clock speeds of the Netburst microarchitecture, even after moving to 45 nm lithography."; 97 | $var1 = "The = Intel = Core"; 98 | $some_url = "http://CentOs:password@intel:8080/go?arg=link#text"; 99 | $test_array1 = preg_split("/[\s,]+/", $var1); 100 | $test_array = preg_split("/[\s,]+/", $var); 101 | 102 | for ($i = 0 ; $i < $STANDARD_CALL_IT; $i++ ) { 103 | error_reporting(E_ERROR | E_WARNING | E_PARSE); 104 | array_walk($test_array, 'do_nothing'); 105 | krsort($test_array); 106 | ksort($test_array); 107 | parse_str($var1); 108 | end($test_array); 109 | reset($test_array); 110 | array_shift($test_array); 111 | array_pop($test_array); 112 | array_diff($test_array1, $test_array); 113 | extract($test_array, EXTR_PREFIX_SAME, "wddx"); 114 | $ks = array_keys($test_array); 115 | 116 | } 117 | 118 | } 119 | function run_ini_set($INI_SET_IT) { 120 | $fname='ini_set'; 121 | for ($i = 0 ; $i < $INI_SET_IT; $i++ ) { 122 | 123 | $fname('set_ini',1); 124 | } 125 | } 126 | 127 | function run_array_map($ARRAY_MAP_IT) { 128 | $test = $GLOBALS['test_array1_g']; 129 | $fname = "array_map"; 130 | for ($i = 0; $i<$ARRAY_MAP_IT; $i++) { 131 | $rez = $fname("replace", $test); 132 | } 133 | } 134 | function run_array_merge($ARRAY_MERGE_IT) { 135 | $test = $GLOBALS['test_array1_g']; 136 | $test1 = $GLOBALS['test_array_g']; 137 | $last = $test; 138 | $fname = "array_merge"; 139 | for ($i = 0; $i<$ARRAY_MERGE_IT; $i++) { 140 | $rez = $fname($test1, $test); 141 | 142 | } 143 | } 144 | function run_preg_match($PREG_MATCH_IT) { 145 | $subject = "abcdef abcdefabcdefabcdef abcdef abcdefabcdefabcdefabcdef abcdefabcdefabcdef abcdef abcdefabcdefabcdef abcdef abcdefabcdefabcdefabcdef abcdefabcdefabcdef"; 146 | $pattern = '/^def/'; 147 | $fname = "preg_match"; 148 | for ($i = 0; $i<$PREG_MATCH_IT; $i++) { 149 | $fname($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); 150 | } 151 | } 152 | 153 | function run_parse_url($PARSE_URL_IT) { 154 | $some_url = $GLOBALS['some_url_g']; 155 | $fname = "parse_url"; 156 | for($i=0; $i < $PARSE_URL_IT; $i++) { 157 | $v = $fname($some_url); 158 | } 159 | } 160 | 161 | function run_version_compare($VERSION_COMPARE_IT) { 162 | for ($i = 0; $i < $VERSION_COMPARE_IT; $i++ ) { 163 | $v1 = version_compare(phpversion(), '5.5', '>='); 164 | $v2 = version_compare(phpversion(), '7.0', '<='); 165 | 166 | } 167 | } 168 | function run_file_exists($FILE_EXISTS_IT) { 169 | for ($i = 0; $i < $FILE_EXISTS_IT; $i++ ) { 170 | 171 | if (file_exists("generic.txt")) { 172 | $v = 1; 173 | } 174 | if (file_exists("not-a-file.txt")) { 175 | $v2 = 2; 176 | } 177 | } 178 | } 179 | function run_file_operations($FILE_OPS_IT) { 180 | $fname = "fopen"; 181 | for ($i = 0; $i < $FILE_OPS_IT; $i++ ) { 182 | $file = $fname("generic.txt", "r"); 183 | $rez = fread($file,"1024"); 184 | fclose($file); 185 | } 186 | } 187 | function run_func_exists($FUNC_EXISTS_IT) { 188 | $fname = "function_exists"; 189 | for ($i=0; $i < $FUNC_EXISTS_IT ; $i++) 190 | if ($fname("version_compare")) 191 | if($fname("run_preg_match")) 192 | if($fname("fff-XXxX")) 193 | { //do nothing 194 | } 195 | } 196 | ?> 197 | -------------------------------------------------------------------------------- /string.php: -------------------------------------------------------------------------------- 1 | 24 | * Bogdan Andone 25 | */ 26 | 27 | /* Constants for scaling the number of runs; 28 | * Users can change these value for tuning execution weights 29 | */ 30 | define('STRING_PREG_REPLACE_IT',15); /* # of preg_replace() calls */ 31 | define('STRING_PREG_REPLACE_CALLBACK_IT',2); /* # of preg_replace_callback() calls */ 32 | define('STRING_STR_REPLACE_IT', 60); /* # of str_replace() calls */ 33 | define('STRING_SPLIT_IT', 10); /* # of split() calls */ 34 | define('STRING_STRTOLOWER_IT', 2); /* # of strtolower() calls */ 35 | define('STRING_CHECKENCODING_IT', 35); /* # of mb_check_encoding() calls */ 36 | define('STRING_IN_ARRAY_IT', 500); /* # of in_array() calls */ 37 | define('STRING_ECHO_IT', 1); /* # echo calls */ 38 | define('STRING_UNSERIALIZE_IT', 1700); /* # of unserialize() calls */ 39 | define('STRING_SERIALIZE_IT', 500); /* # of serialize() calls */ 40 | define('STRING_TRIM_IT', 15000); /* # of trim() calls */ 41 | define('STRING_CONCAT_IT',1); /* # string concat - not as side effect*/ 42 | define('STRING_MD5_IT', 100); /* # of md5() calls */ 43 | define('STRING_IMPLODE_IT', 1000); /* # of implode() calls */ 44 | 45 | /** 46 | * This php file contains calls to standard string processing functions. 47 | * Each standard call function have a "run_string_" prefix. 48 | */ 49 | $split_strings = array(); 50 | 51 | function string_register_training(& $functions) 52 | { 53 | /* goto next benchmark module if any of standard, 54 | * mbstring or pcre extensions are missing 55 | */ 56 | if (!extension_loaded("standard")) { 57 | echo " String benchmark module not loaded: standard extension is missing\n"; 58 | return -1; 59 | } 60 | if (!extension_loaded("mbstring")) { 61 | echo " String benchmark not module loaded: mbstring extension is missing\n"; 62 | return -1; 63 | } 64 | 65 | if (!extension_loaded("pcre")) { 66 | echo " String benchmark module not loaded: pcre extension is missing\n"; 67 | return -1; 68 | } 69 | echo "String benchmark module loaded!\n"; 70 | $functions[] = "run_string"; 71 | } 72 | 73 | /** 74 | * Calls all string processing functions from this module 75 | */ 76 | function run_string() { 77 | 78 | /* Six strings variables and an array used as parameters 79 | * to string processing functions 80 | */ 81 | $s0 = "Uranium is a chemical element with symbol U and atomic number 92. 82 | It is a silvery-white metal in the actinide series of the periodic table. 83 | A uranium atom has 92 protons and 92 electrons, of which 6 are valence electrons. 84 | Uranium is weakly radioactive because all its isotopes are unstable (with half-lives 85 | of the six naturally known isotopes, uranium-233 to uranium-238, varying between 69 86 | years and 4.5 billion years). The most common isotopes of uranium are uranium-238 87 | (which has 146 neutrons and accounts for almost 99.3% of the uranium found in nature) 88 | and uranium-235 (which has 143 neutrons, accounting for 0.7% of the element found naturally)."; 89 | 90 | // ark.intel.com disclaimer 91 | $s1 = "All information provided is subject to change at any time, without notice. Intel may make changes to manufacturing life cycle, specifications, and product descriptions at any time, without notice. The information herein is provided as-is and Intel does not make any representations or warranties whatsoever regarding accuracy of the information, nor on the product features, availability, functionality, or compatibility of the products listed. Please contact system vendor for more information on specific products or systems."; 92 | 93 | // copy-pasta string 94 | $s2 = "php benchmark php benchmark php pgo benchmark php pgo benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark pgo php benchmark pgo php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark php benchmark { 95 | php benchmark php benchmark php benchmark php benchmark pgo php benchmark php benchmark php benchmark pgo php benchmark php benchmark php benchmark php benchmark pgo php benchmark }"; 96 | 97 | // random numbers string 98 | $s3 = "2459 99 | 2410 100 | 0733 101 | 1929 102 | 3572 103 | 0215 104 | 3177 105 | 4755 106 | 2142 107 | 9552 108 | 7666 109 | 9170 110 | 1228 111 | 6619 112 | 6786 113 | 3643 114 | 0727 115 | 3622 116 | 8176 117 | 0395 118 | 0968 119 | 1290 120 | 0356 121 | 3847 122 | 3738 123 | 7112 124 | 1400 125 | 3991 126 | 4314 127 | 8481"; 128 | 129 | // random letters string 130 | $s4 = "FVVLV 131 | KMGDL 132 | BUCGC 133 | RYOZY 134 | EJKLH 135 | VYDCY 136 | GXVTJ 137 | DOSHX 138 | JTISW 139 | FFVSI 140 | OQISD 141 | JXFKA 142 | AMRXI 143 | TTXXV 144 | CACIX 145 | ERWHL 146 | LUXUW 147 | MBWNS 148 | XWUEZ 149 | GAABL 150 | VWPGG 151 | IVQHQ 152 | QUTUK 153 | NZAIU 154 | CHSYU 155 | GWBPM 156 | KKXGY 157 | MIUSN 158 | HHZBZ 159 | RTORR"; 160 | 161 | 162 | $s5 = " { } 163 | if (a == b) { 164 | //do something 165 | ++a; 166 | } else { 167 | b +=a; 168 | } } 169 | "; 170 | 171 | // Wikipedia.org Intel Core(microarchitecture) 172 | $s6 = "The Intel Core microarchitecture (previously known as the Next-Generation Micro-Architecture) is a multi-core processor microarchitecture unveiled by Intel in Q1 2006. It is based on the Yonah processor design and can be considered an iteration of the P6 microarchitecture, introduced in 1995 with Pentium Pro. The high power consumption and heat intensity, the resulting inability to effectively increase clock speed, and other shortcomings such as the inefficient pipeline were the primary reasons for which Intel abandoned the NetBurst microarchitecture and switched to completely different architectural design, delivering high efficiency through a small pipeline rather than high clock speeds. The Core microarchitecture never reached the clock speeds of the Netburst microarchitecture, even after moving to 45 nm lithography. 173 | The first processors that used this architecture were code-named 'Merom', 'Conroe', and 'Woodcrest'; Merom is for mobile computing, Conroe is for desktop systems, and Woodcrest is for servers and workstations. While architecturally identical, the three processor lines differ in the socket used, bus speed, and power consumption. Mainstream Core-based processors are branded Pentium Dual-Core or Pentium and low end branded Celeron; server and workstation Core-based processors are branded Xeon, while desktop and mobile Core-based processors are branded as Core 2. Despite their names, processors sold as Core Solo/Core Duo and Core i3/i5/i7 do not actually use the Core microarchitecture and are based on the Enhanced Pentium M and newer Nehalem/Sandy Bridge/Haswell/Skylake microarchitectures, respectively. 174 | The Core microarchitecture returned to lower clock rates and improved the usage of both available clock cycles and power when compared with the preceding NetBurst microarchitecture of the Pentium 4/D-branded CPUs.[1] The Core microarchitecture provides more efficient decoding stages, execution units, caches, and buses, reducing the power consumption of Core 2-branded CPUs while increasing their processing capacity. Intel's CPUs have varied widely in power consumption according to clock rate, architecture, and semiconductor process, shown in the CPU power dissipation tables. 175 | Like the last NetBurst CPUs, Core based processors feature multiple cores and hardware virtualization support (marketed as Intel VT-x), as well as Intel 64 and SSSE3. However, Core-based processors do not have the Hyper-Threading Technology found in Pentium 4 processors. This is because the Core microarchitecture is a descendant of the P6 microarchitecture used by Pentium Pro, Pentium II, Pentium III, and Pentium M. 176 | The L1 cache size was enlarged in the Core microarchitecture, from 32 KB on Pentium II/III (16 KB L1 Data + 16 KB L1 Instruction) to 64 KB L1 cache/core (32 KB L1 Data + 32 KB L1 Instruction) on Pentium M and Core/Core 2. It also lacks an L3 Cache found in the Gallatin core of the Pentium 4 Extreme Edition, although an L3 Cache is present in high-end versions of Core-based Xeons. Both an L3 cache and Hyper-threading were reintroduced in the Nehalem microarchitecture."; 177 | 178 | $s7 = " _______ _______ _______ _______ _ _______ 179 | ( ____ \|\ /|( ___ )( )( ____ )( \ ( ____ \ 180 | | ( \/( \ / )| ( ) || () () || ( )|| ( | ( \/ 181 | | (__ \ (_) / | (___) || || || || (____)|| | | (__ 182 | | __) ) _ ( | ___ || |(_)| || _____)| | | __) 183 | | ( / ( ) \ | ( ) || | | || ( | | | ( 184 | | (____/\( / \ )| ) ( || ) ( || ) | (____/\| (____/\ 185 | (_______/|/ \||/ \||/ \||/ (_______/(_______/ 186 | "; 187 | $strings = array($s0, $s1, $s2, $s3, $s4, $s5, $s6, $s7); 188 | 189 | run_string_preg_replace($strings); 190 | run_string_preg_replace_callback($strings); 191 | run_string_preg_split($strings); 192 | run_string_strtolower($strings); 193 | run_string_check_encoding($strings); 194 | run_string_str_replace($strings); 195 | run_string_in_array($strings); 196 | run_unserialize($strings); 197 | run_string_trim($s5); 198 | run_string_md5($s6); 199 | run_string_implode($strings); 200 | 201 | } 202 | function repcb($matches) { 203 | return "s"; 204 | } 205 | 206 | function run_unserialize($strings_array) { 207 | $ser_array = serialize($strings_array); 208 | $ser_no = STRING_SERIALIZE_IT; 209 | 210 | for ($i=0; $i < STRING_SERIALIZE_IT; $i++) { 211 | $ser_array = serialize($strings_array); 212 | } 213 | 214 | for ($i=0; $i < STRING_UNSERIALIZE_IT; $i++) { 215 | $var = unserialize($ser_array); 216 | } 217 | } 218 | 219 | function run_string_preg_replace($strs) { 220 | $patterns = array("/process/", "/Intel/", "/10/", "/DOS/", "/uranium/", "/php/"); 221 | $replacements = array("thread", "Spark", "12", "MS", "Iron", "python"); 222 | 223 | $len = sizeof($strs); 224 | for ($i = 0; $i < STRING_PREG_REPLACE_IT ;$i++){ 225 | for ($j=0; $j < $len; $j++) { 226 | $rez = preg_replace($patterns, $replacements, $strs[$j]); 227 | $rez = preg_replace('/\s+/', '_', $rez); 228 | $rez1 = preg_replace('/[1-9]/', "1", $strs[$j]); 229 | $rez2 = preg_replace('/[A-Z]/', "_",$rez1); 230 | $rez3 = preg_replace('/[a-z]+/', "*", $rez2); 231 | //echo $rez3; 232 | } 233 | 234 | } 235 | } 236 | function run_string_preg_replace_callback($strs) { 237 | 238 | $patterns = array("/process/", "/Intel/", "/10/", "/DOS/", "/uranium/", "/php/"); 239 | $replacements = array("thread", "Spark", "12", "MS", "Iron", "python"); 240 | 241 | $len = sizeof($strs); 242 | for ($i = 0; $i < STRING_PREG_REPLACE_CALLBACK_IT ;$i++){ 243 | for ($j=0; $j < $len; $j++) { 244 | $rez = preg_replace_callback($patterns, 'repcb', $strs[$j]); 245 | $rez = preg_replace_callback('/\s+/', 'repcb', $rez); 246 | $rez1 = preg_replace_callback('/[1-9]/', 'repcb', $strs[$j]); 247 | $rez2 = preg_replace_callback('/[A-Z]/', 'repcb',$rez1); 248 | $rez3 = preg_replace_callback('/[a-z]+/', 'repcb', $rez2); 249 | } 250 | } 251 | } 252 | function run_string_str_replace($strs) { 253 | 254 | $patterns = array("/process/", "/Intel/", "/10/", "/DOS/", "/uranium/", "/php/"); 255 | $replacements = array("thread", "Spark", "12", "MS", "Iron", "python"); 256 | 257 | $len = sizeof($strs); 258 | for ($i = 0; $i < STRING_STR_REPLACE_IT ;$i++){ 259 | for ($j=0; $j < $len; $j++) { 260 | $rez = str_replace($patterns, $replacements, $strs[$j]); 261 | $rez = str_replace('/\s+/', '_', $rez); 262 | $rez1 = str_replace('/[1-9]/', "1", $strs[$j]); 263 | $rez2 = str_replace('/[A-Z]/', "_",$rez1); 264 | $rez3 = str_replace('/[a-z]+/', "*", $rez2); 265 | } 266 | 267 | } 268 | } 269 | 270 | function run_string_preg_split($strs) { 271 | $len = sizeof($strs); 272 | $GLOBALS['split_strings'] = array(); 273 | for ($i = 0; $i < STRING_SPLIT_IT ;$i++){ 274 | for ($j=0; $j < $len; $j++) { 275 | $keywords = preg_split("/[\s,]+/", $strs[$j]); 276 | if ($i == 0 && $j==0) 277 | array_push($GLOBALS['split_strings'], $keywords); 278 | } 279 | 280 | } 281 | 282 | } 283 | function run_string_strtolower($strs) { 284 | $len = sizeof($strs); 285 | for ($i = 0; $i < STRING_STRTOLOWER_IT ;$i++){ 286 | for ($j=0; $j < $len; $j++) { 287 | $val = mb_strtolower($strs[$j]); 288 | } 289 | } 290 | } 291 | 292 | function run_string_in_array($strs) { 293 | $strs = $GLOBALS['split_strings']; 294 | $len = sizeof($strs); 295 | for ($i = 0; $i < STRING_IN_ARRAY_IT ;$i++){ 296 | for ($j=0; $j < $len; $j++) { 297 | $ret_val = in_array("a", $strs[$j]); 298 | $ret_val1 = in_array("1", $strs[$j]); 299 | $ret_val2 = in_array("the", $strs[$j]); 300 | $ret_val3 = in_array("The", $strs[$j]); 301 | $ret_val4 = in_array("Intel", $strs[$j]); 302 | $ret_val5 = in_array("php", $strs[$j]); 303 | } 304 | } 305 | unset($GLOBALS['split_strings']); 306 | } 307 | 308 | function run_string_check_encoding($strs) { 309 | $len = sizeof($strs); 310 | for ($i = 0; $i < STRING_CHECKENCODING_IT ;$i++){ 311 | for ($j=0; $j < $len; $j++) { 312 | if (function_exists('mb_check_encoding')) { 313 | if (mb_check_encoding($strs[$j], 'ASCII')){ 314 | $x = $strs[$j][0]; 315 | } 316 | } 317 | } 318 | } 319 | } 320 | function run_string_echo($strs) { 321 | $strs = $GLOBALS['split_strings']; 322 | $len = sizeof($strs); 323 | for ($i = 0; $i < STRING_ECHO_IT ;$i++){ 324 | for ($j=0; $j < $len; $j++) { 325 | $num_tokens = sizeof($strs[$j]); 326 | for ($k = 0; $k < $num_tokens; $k++) { 327 | echo $strs[$j][$k] . " " . $strs[$j][$k]; 328 | } 329 | } 330 | } 331 | } 332 | 333 | function run_string_concat($strs) { 334 | 335 | for($i = 0; $i < STRING_CONCAT_IT; $i++) { 336 | $var = STRING_ECHO_IT . ' ' . STRING_CHECKENCODING_IT . ' ' . STRING_STRTOLOWER_IT . "/this/is/some/random/path"; 337 | $var1 = $var . ' - ' . $GLOBALS['s7']; 338 | $var2 = "I am happy." . "\n" . "You are " . SQL_QUERIES_IT . "x happier "; 339 | $num_var = 32; 340 | $ret = $var1 . (string) $num_var; 341 | } 342 | 343 | } 344 | 345 | function run_string_trim($str) { 346 | for($i = 0; $i < STRING_TRIM_IT; $i++) { 347 | $s = trim($str, " \t\n}{"); 348 | } 349 | } 350 | 351 | function run_string_md5($str) { 352 | for($i = 0; $i < STRING_MD5_IT; $i++) { 353 | $s = md5($str); 354 | } 355 | } 356 | 357 | function run_string_implode($strings_array) { 358 | for($i = 0; $i < STRING_IMPLODE_IT; $i++) { 359 | $s = implode($strings_array); 360 | } 361 | } 362 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | PHP PGO Training - to be used during Profile Guided Optimization builds. 2 | Copyright (C) 2016 Intel Corporation 3 | 4 | This program is free software and open source software; you can redistribute 5 | it and/or modify it under the terms of the GNU General Public License as 6 | published by the Free Software Foundation; either version 2 of the License, 7 | or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but WITHOUT 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 | http://www.gnu.org/licenses/gpl.html 18 | 19 | This program incorporates work covered by the following copyright and 20 | permission notices: 21 | 22 | WordPress - Web publishing software 23 | Copyright 2003-2010 by the contributors 24 | WordPress is released under the GPL 25 | 26 | =============================================================================== 27 | 28 | GNU GENERAL PUBLIC LICENSE 29 | Version 2, June 1991 30 | 31 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 32 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 | Everyone is permitted to copy and distribute verbatim copies 34 | of this license document, but changing it is not allowed. 35 | 36 | Preamble 37 | 38 | The licenses for most software are designed to take away your 39 | freedom to share and change it. By contrast, the GNU General Public 40 | License is intended to guarantee your freedom to share and change free 41 | software--to make sure the software is free for all its users. This 42 | General Public License applies to most of the Free Software 43 | Foundation's software and to any other program whose authors commit to 44 | using it. (Some other Free Software Foundation software is covered by 45 | the GNU Lesser General Public License instead.) You can apply it to 46 | your programs, too. 47 | 48 | When we speak of free software, we are referring to freedom, not 49 | price. Our General Public Licenses are designed to make sure that you 50 | have the freedom to distribute copies of free software (and charge for 51 | this service if you wish), that you receive source code or can get it 52 | if you want it, that you can change the software or use pieces of it 53 | in new free programs; and that you know you can do these things. 54 | 55 | To protect your rights, we need to make restrictions that forbid 56 | anyone to deny you these rights or to ask you to surrender the rights. 57 | These restrictions translate to certain responsibilities for you if you 58 | distribute copies of the software, or if you modify it. 59 | 60 | For example, if you distribute copies of such a program, whether 61 | gratis or for a fee, you must give the recipients all the rights that 62 | you have. You must make sure that they, too, receive or can get the 63 | source code. And you must show them these terms so they know their 64 | rights. 65 | 66 | We protect your rights with two steps: (1) copyright the software, and 67 | (2) offer you this license which gives you legal permission to copy, 68 | distribute and/or modify the software. 69 | 70 | Also, for each author's protection and ours, we want to make certain 71 | that everyone understands that there is no warranty for this free 72 | software. If the software is modified by someone else and passed on, we 73 | want its recipients to know that what they have is not the original, so 74 | that any problems introduced by others will not reflect on the original 75 | authors' reputations. 76 | 77 | Finally, any free program is threatened constantly by software 78 | patents. We wish to avoid the danger that redistributors of a free 79 | program will individually obtain patent licenses, in effect making the 80 | program proprietary. To prevent this, we have made it clear that any 81 | patent must be licensed for everyone's free use or not licensed at all. 82 | 83 | The precise terms and conditions for copying, distribution and 84 | modification follow. 85 | 86 | GNU GENERAL PUBLIC LICENSE 87 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 88 | 89 | 0. This License applies to any program or other work which contains 90 | a notice placed by the copyright holder saying it may be distributed 91 | under the terms of this General Public License. The "Program", below, 92 | refers to any such program or work, and a "work based on the Program" 93 | means either the Program or any derivative work under copyright law: 94 | that is to say, a work containing the Program or a portion of it, 95 | either verbatim or with modifications and/or translated into another 96 | language. (Hereinafter, translation is included without limitation in 97 | the term "modification".) Each licensee is addressed as "you". 98 | 99 | Activities other than copying, distribution and modification are not 100 | covered by this License; they are outside its scope. The act of 101 | running the Program is not restricted, and the output from the Program 102 | is covered only if its contents constitute a work based on the 103 | Program (independent of having been made by running the Program). 104 | Whether that is true depends on what the Program does. 105 | 106 | 1. You may copy and distribute verbatim copies of the Program's 107 | source code as you receive it, in any medium, provided that you 108 | conspicuously and appropriately publish on each copy an appropriate 109 | copyright notice and disclaimer of warranty; keep intact all the 110 | notices that refer to this License and to the absence of any warranty; 111 | and give any other recipients of the Program a copy of this License 112 | along with the Program. 113 | 114 | You may charge a fee for the physical act of transferring a copy, and 115 | you may at your option offer warranty protection in exchange for a fee. 116 | 117 | 2. You may modify your copy or copies of the Program or any portion 118 | of it, thus forming a work based on the Program, and copy and 119 | distribute such modifications or work under the terms of Section 1 120 | above, provided that you also meet all of these conditions: 121 | 122 | a) You must cause the modified files to carry prominent notices 123 | stating that you changed the files and the date of any change. 124 | 125 | b) You must cause any work that you distribute or publish, that in 126 | whole or in part contains or is derived from the Program or any 127 | part thereof, to be licensed as a whole at no charge to all third 128 | parties under the terms of this License. 129 | 130 | c) If the modified program normally reads commands interactively 131 | when run, you must cause it, when started running for such 132 | interactive use in the most ordinary way, to print or display an 133 | announcement including an appropriate copyright notice and a 134 | notice that there is no warranty (or else, saying that you provide 135 | a warranty) and that users may redistribute the program under 136 | these conditions, and telling the user how to view a copy of this 137 | License. (Exception: if the Program itself is interactive but 138 | does not normally print such an announcement, your work based on 139 | the Program is not required to print an announcement.) 140 | 141 | These requirements apply to the modified work as a whole. If 142 | identifiable sections of that work are not derived from the Program, 143 | and can be reasonably considered independent and separate works in 144 | themselves, then this License, and its terms, do not apply to those 145 | sections when you distribute them as separate works. But when you 146 | distribute the same sections as part of a whole which is a work based 147 | on the Program, the distribution of the whole must be on the terms of 148 | this License, whose permissions for other licensees extend to the 149 | entire whole, and thus to each and every part regardless of who wrote it. 150 | 151 | Thus, it is not the intent of this section to claim rights or contest 152 | your rights to work written entirely by you; rather, the intent is to 153 | exercise the right to control the distribution of derivative or 154 | collective works based on the Program. 155 | 156 | In addition, mere aggregation of another work not based on the Program 157 | with the Program (or with a work based on the Program) on a volume of 158 | a storage or distribution medium does not bring the other work under 159 | the scope of this License. 160 | 161 | 3. You may copy and distribute the Program (or a work based on it, 162 | under Section 2) in object code or executable form under the terms of 163 | Sections 1 and 2 above provided that you also do one of the following: 164 | 165 | a) Accompany it with the complete corresponding machine-readable 166 | source code, which must be distributed under the terms of Sections 167 | 1 and 2 above on a medium customarily used for software interchange; or, 168 | 169 | b) Accompany it with a written offer, valid for at least three 170 | years, to give any third party, for a charge no more than your 171 | cost of physically performing source distribution, a complete 172 | machine-readable copy of the corresponding source code, to be 173 | distributed under the terms of Sections 1 and 2 above on a medium 174 | customarily used for software interchange; or, 175 | 176 | c) Accompany it with the information you received as to the offer 177 | to distribute corresponding source code. (This alternative is 178 | allowed only for noncommercial distribution and only if you 179 | received the program in object code or executable form with such 180 | an offer, in accord with Subsection b above.) 181 | 182 | The source code for a work means the preferred form of the work for 183 | making modifications to it. For an executable work, complete source 184 | code means all the source code for all modules it contains, plus any 185 | associated interface definition files, plus the scripts used to 186 | control compilation and installation of the executable. However, as a 187 | special exception, the source code distributed need not include 188 | anything that is normally distributed (in either source or binary 189 | form) with the major components (compiler, kernel, and so on) of the 190 | operating system on which the executable runs, unless that component 191 | itself accompanies the executable. 192 | 193 | If distribution of executable or object code is made by offering 194 | access to copy from a designated place, then offering equivalent 195 | access to copy the source code from the same place counts as 196 | distribution of the source code, even though third parties are not 197 | compelled to copy the source along with the object code. 198 | 199 | 4. You may not copy, modify, sublicense, or distribute the Program 200 | except as expressly provided under this License. Any attempt 201 | otherwise to copy, modify, sublicense or distribute the Program is 202 | void, and will automatically terminate your rights under this License. 203 | However, parties who have received copies, or rights, from you under 204 | this License will not have their licenses terminated so long as such 205 | parties remain in full compliance. 206 | 207 | 5. You are not required to accept this License, since you have not 208 | signed it. However, nothing else grants you permission to modify or 209 | distribute the Program or its derivative works. These actions are 210 | prohibited by law if you do not accept this License. Therefore, by 211 | modifying or distributing the Program (or any work based on the 212 | Program), you indicate your acceptance of this License to do so, and 213 | all its terms and conditions for copying, distributing or modifying 214 | the Program or works based on it. 215 | 216 | 6. Each time you redistribute the Program (or any work based on the 217 | Program), the recipient automatically receives a license from the 218 | original licensor to copy, distribute or modify the Program subject to 219 | these terms and conditions. You may not impose any further 220 | restrictions on the recipients' exercise of the rights granted herein. 221 | You are not responsible for enforcing compliance by third parties to 222 | this License. 223 | 224 | 7. If, as a consequence of a court judgment or allegation of patent 225 | infringement or for any other reason (not limited to patent issues), 226 | conditions are imposed on you (whether by court order, agreement or 227 | otherwise) that contradict the conditions of this License, they do not 228 | excuse you from the conditions of this License. If you cannot 229 | distribute so as to satisfy simultaneously your obligations under this 230 | License and any other pertinent obligations, then as a consequence you 231 | may not distribute the Program at all. For example, if a patent 232 | license would not permit royalty-free redistribution of the Program by 233 | all those who receive copies directly or indirectly through you, then 234 | the only way you could satisfy both it and this License would be to 235 | refrain entirely from distribution of the Program. 236 | 237 | If any portion of this section is held invalid or unenforceable under 238 | any particular circumstance, the balance of the section is intended to 239 | apply and the section as a whole is intended to apply in other 240 | circumstances. 241 | 242 | It is not the purpose of this section to induce you to infringe any 243 | patents or other property right claims or to contest validity of any 244 | such claims; this section has the sole purpose of protecting the 245 | integrity of the free software distribution system, which is 246 | implemented by public license practices. Many people have made 247 | generous contributions to the wide range of software distributed 248 | through that system in reliance on consistent application of that 249 | system; it is up to the author/donor to decide if he or she is willing 250 | to distribute software through any other system and a licensee cannot 251 | impose that choice. 252 | 253 | This section is intended to make thoroughly clear what is believed to 254 | be a consequence of the rest of this License. 255 | 256 | 8. If the distribution and/or use of the Program is restricted in 257 | certain countries either by patents or by copyrighted interfaces, the 258 | original copyright holder who places the Program under this License 259 | may add an explicit geographical distribution limitation excluding 260 | those countries, so that distribution is permitted only in or among 261 | countries not thus excluded. In such case, this License incorporates 262 | the limitation as if written in the body of this License. 263 | 264 | 9. The Free Software Foundation may publish revised and/or new versions 265 | of the General Public License from time to time. Such new versions will 266 | be similar in spirit to the present version, but may differ in detail to 267 | address new problems or concerns. 268 | 269 | Each version is given a distinguishing version number. If the Program 270 | specifies a version number of this License which applies to it and "any 271 | later version", you have the option of following the terms and conditions 272 | either of that version or of any later version published by the Free 273 | Software Foundation. If the Program does not specify a version number of 274 | this License, you may choose any version ever published by the Free Software 275 | Foundation. 276 | 277 | 10. If you wish to incorporate parts of the Program into other free 278 | programs whose distribution conditions are different, write to the author 279 | to ask for permission. For software which is copyrighted by the Free 280 | Software Foundation, write to the Free Software Foundation; we sometimes 281 | make exceptions for this. Our decision will be guided by the two goals 282 | of preserving the free status of all derivatives of our free software and 283 | of promoting the sharing and reuse of software generally. 284 | 285 | NO WARRANTY 286 | 287 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 288 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 289 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 290 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 291 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 292 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 293 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 294 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 295 | REPAIR OR CORRECTION. 296 | 297 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 298 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 299 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 300 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 301 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 302 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 303 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 304 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 305 | POSSIBILITY OF SUCH DAMAGES. 306 | 307 | END OF TERMS AND CONDITIONS 308 | 309 | -------------------------------------------------------------------------------- /db.php: -------------------------------------------------------------------------------- 1 | 28 | * Bogdan Andone 29 | */ 30 | 31 | /* Constants for scaling the number of runs; 32 | * Users can change these value for tuning execution weights 33 | */ 34 | define('SQL_QUERIES_IT', 40); /* how many times sql module will run */ 35 | 36 | 37 | define( 'OBJECT_K', 'OBJECT_K' ); 38 | define( 'ARRAY_A', 'ARRAY_A' ); 39 | define( 'ARRAY_N', 'ARRAY_N' ); 40 | define( 'OBJECT', 'OBJECT' ); 41 | define( 'object', 'OBJECT' ); // Back compat. 42 | 43 | function mysql_register_training(& $functions) 44 | { 45 | /* if extension is missing goto next bench module */ 46 | if (!extension_loaded("mysqli")) { 47 | echo " MySQL benchmark module not loaded: mysqli extension is missing\n"; 48 | return -1; 49 | } 50 | /* check if a connection to DB is possible */ 51 | $handler = new mysqli(DB_HOST, DB_USER, DB_PASSWORD); 52 | if ( $handler->connect_errno ) { 53 | $handler = null; 54 | die(" MySQL benchmark module not loaded: Wrong credentials.\n". 55 | "Make sure the following constants in constants.php are correct: DB_USER, DB_PASSWORD, DB_NAME, DB_HOST.\n"); 56 | } else { 57 | $success = @mysqli_select_db($handler, DB_NAME); 58 | if (!$success) { 59 | $handler->close(); 60 | die(" MySQL benchmark module not loaded: Failed to select database.\n". 61 | "Make sure you call: /php init.php\n"); 62 | } 63 | } 64 | $handler->close(); 65 | 66 | echo "MySQL benchmark module loaded!\n"; 67 | $functions[] = "run_mysql_queries"; 68 | } 69 | 70 | /** 71 | * Calls Mysql functions from db.php 72 | */ 73 | function run_mysql_queries() { 74 | $newDB = new db(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 75 | if (!$newDB->check_connection()) 76 | die("Connection failed.\n". 77 | "Make sure the following constants in constants.php are correct: DB_USER, DB_PASSWORD, DB_NAME, DB_HOST.\n". 78 | "Make sure you call: /php init.php\n". 79 | "!!!Attention: restart training process from scratch(make clean && make pgo-train)"); 80 | else { 81 | $names = array("\"WinnieThePooh\"" , "\"Mickey Mouse\"", "\"something\"", "\"random_name\"", "\"YetAnotherName\"", "\"NotINTable\""); 82 | for ($i=0; $i < SQL_QUERIES_IT; $i++) { 83 | first_query($newDB); 84 | second_query($newDB); 85 | for ($j = 0; $j < 10; $j++){ 86 | select_simple_WHERE($newDB, " * ", "col2", $names[$j%6]); 87 | } 88 | select_INNER_JOIN($newDB); 89 | multiple_WHERE_CLAUSES($newDB); 90 | } 91 | } 92 | } 93 | class db { 94 | 95 | var $show_errors = false; 96 | var $last_error = ''; // last error during query 97 | var $num_queries = 0; // amount of queries made 98 | var $rows_affected = 0; // count of affected rows by previous query 99 | var $insert_id = 0; // ID generated for AUTO_INCREMEND column 100 | var $last_query; // last query made 101 | var $last_result; // result of the last query made 102 | var $result; 103 | var $queries; // queries that were executed 104 | var $ready = false; //queries are ready to start executing 105 | var $tables = array( 'table_one', 'table_two', 'table_three'); 106 | var $reconnect_retries = 2; 107 | protected $dbuser; 108 | protected $dbpassword; 109 | protected $dbname; 110 | protected $dbhost; 111 | protected $dbhandle; 112 | private $has_connected = false; 113 | private $use_mysqli = false; 114 | public $table_one; 115 | public $table_two; 116 | public $table_three; 117 | 118 | public function __construct($user, $pass, $dbname, $dbhost) { 119 | register_shutdown_function( array( $this, '__destruct' ) ); 120 | 121 | if (function_exists('mysqli_connect')) { 122 | $this -> use_mysqli = true; 123 | } 124 | 125 | $this->dbuser = $user; 126 | $this->dbpassword = $pass; 127 | $this->dbname = $dbname; 128 | $this->dbhost = $dbhost; 129 | 130 | $this->init(); 131 | $this->db_connect(); 132 | } 133 | 134 | public function __destruct() { 135 | return true; 136 | } 137 | 138 | public function init() { 139 | $this->tables = array( 'table_one', 'table_two', 'table_three'); 140 | $this->table_one = 'table_one'; 141 | $this->table_two = 'table_two'; 142 | $this->table_three = 'table_three'; 143 | 144 | } 145 | public function db_connect() { 146 | 147 | $new_link = true; 148 | $client_flags = 0; 149 | 150 | if( $this->use_mysqli ) { 151 | // mysqli_real_connect doesn't support the host param including a port or socket 152 | // like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file. 153 | $port = null; 154 | $socket = null; 155 | $host = $this->dbhost; 156 | $port_or_socket = strstr( $host, ':' ); 157 | if ( ! empty( $port_or_socket ) ) { 158 | $host = substr( $host, 0, strpos( $host, ':' ) ); 159 | $port_or_socket = substr( $port_or_socket, 1 ); 160 | if ( 0 !== strpos( $port_or_socket, '/' ) ) { 161 | $port = intval( $port_or_socket ); 162 | $maybe_socket = strstr( $port_or_socket, ':' ); 163 | if ( ! empty( $maybe_socket ) ) { 164 | $socket = substr( $maybe_socket, 1 ); 165 | } 166 | } else { 167 | $socket = $port_or_socket; 168 | } 169 | } 170 | 171 | //@mysqli_real_connect( $this->dbhandle, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); 172 | $this->dbhandle = new mysqli(DB_HOST, DB_USER, DB_PASSWORD); 173 | if ( $this->dbhandle->connect_errno ) { 174 | $this->dbhandle = null; 175 | die("Connection failed.\n". 176 | "Make sure the following constants in constants.php are correct: DB_USER, DB_PASSWORD, DB_NAME, DB_HOST.\n". 177 | "Make sure you call: /php init.php\n". 178 | "!!!Attention: restart training process from scratch(make clean && make pgo-train)");return false; 179 | 180 | } elseif ( $this->dbhandle ) { 181 | //echo "Connected to " . DB_NAME . "!\n"; 182 | $this->has_connected = true; 183 | $this->ready = true; 184 | $this->select($this->dbname, $this->dbhandle); 185 | return true; 186 | } 187 | } 188 | return false; 189 | } 190 | 191 | public function select($db, $dbh = null) { 192 | if (is_null($dbh)) { 193 | $dbh = $this->dbhandle; 194 | } 195 | if ($this->use_mysqli) { 196 | $success = @mysqli_select_db( $dbh, $db ); 197 | } 198 | else { 199 | $success = @mysqli_select_db( $db, $dbh ); 200 | } 201 | if (!$success) { 202 | $this->ready = false; 203 | die("Error: db_select_fail"); 204 | return false; 205 | } 206 | } 207 | 208 | public function flush() { 209 | $this->last_result = array(); 210 | $this->last_query = null; 211 | $this->rows_affected = $this->num_rows = 0; 212 | $this->last_error = ''; 213 | 214 | if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { 215 | mysqli_free_result( $this->result ); 216 | $this->result = null; 217 | 218 | // Sanity check before using the handle 219 | if ( empty( $this->dbhandle ) || !( $this->dbhandle instanceof mysqli ) ) { 220 | return; 221 | } 222 | 223 | // Clear out any results from a multi-query 224 | while ( mysqli_more_results( $this->dbhandle ) ) { 225 | mysqli_next_result( $this->dbhandle ); 226 | } 227 | } elseif ( is_resource( $this->result ) ) { 228 | mysql_free_result( $this->result ); 229 | } 230 | } 231 | 232 | private function _do_query( $query ) { 233 | if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { 234 | $this->timer_start(); 235 | } 236 | 237 | if ( $this->use_mysqli ) { 238 | $this->result = @mysqli_query( $this->dbhandle, $query ); 239 | } else { 240 | $this->result = @mysql_query( $query, $this->dbhandle ); 241 | } 242 | $this->num_queries++; 243 | } 244 | 245 | public function check_connection( $allow_bail = true ) { 246 | if ( $this->use_mysqli ) { 247 | if ( @mysqli_ping( $this->dbhandle ) ) { 248 | return true; 249 | } 250 | } else { 251 | if ( @mysql_ping( $this->dbhandle ) ) { 252 | return true; 253 | } 254 | } 255 | 256 | for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) { 257 | // On the last try, re-enable warnings. We want to see a single instance of the 258 | // "unable to connect" message on the bail() screen, if it appears. 259 | if ( $this->db_connect() ) { 260 | return true; 261 | } 262 | sleep( 1 ); 263 | } 264 | } 265 | 266 | public function query( $query ) { 267 | if ( ! $this->ready ) { 268 | $this->check_current_query = true; 269 | return false; 270 | } 271 | 272 | $this->flush(); 273 | 274 | // Keep track of the last query for debug.. 275 | $this->last_query = $query; 276 | 277 | $this->_do_query( $query ); 278 | 279 | // MySQL server has gone away, try to reconnect 280 | $mysql_errno = 0; 281 | if ( ! empty( $this->dbhandle ) ) { 282 | if ( $this->use_mysqli ) { 283 | $mysql_errno = mysqli_errno( $this->dbhandle ); 284 | } else { 285 | $mysql_errno = mysql_errno( $this->dbhandle ); 286 | } 287 | } 288 | 289 | if ( empty( $this->dbhandle ) || 2006 == $mysql_errno ) { 290 | if ( $this->check_connection() ) { 291 | $this->_do_query( $query ); 292 | } else { 293 | $this->insert_id = 0; 294 | return false; 295 | } 296 | } 297 | 298 | // If there is an error then take note of it.. 299 | if ( $this->use_mysqli ) { 300 | $this->last_error = mysqli_error( $this->dbhandle ); 301 | } else { 302 | $this->last_error = mysql_error( $this->dbhandle ); 303 | } 304 | 305 | if ( $this->last_error ) { 306 | // Clear insert_id on a subsequent failed insert. 307 | if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) 308 | $this->insert_id = 0; 309 | 310 | echo $this->dbhandle->error; 311 | die("\nerror\n"); 312 | return false; 313 | } 314 | 315 | if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 316 | $return_val = $this->result; 317 | } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 318 | if ( $this->use_mysqli ) { 319 | $this->rows_affected = mysqli_affected_rows( $this->dbhandle ); 320 | } else { 321 | $this->rows_affected = mysql_affected_rows( $this->dbhandle ); 322 | } 323 | // Take note of the insert_id 324 | if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 325 | if ( $this->use_mysqli ) { 326 | $this->insert_id = mysqli_insert_id( $this->dbhandle ); 327 | } else { 328 | $this->insert_id = mysql_insert_id( $this->dbhandle ); 329 | } 330 | } 331 | // Return number of rows affected 332 | $return_val = $this->rows_affected; 333 | } else { 334 | $num_rows = 0; 335 | if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { 336 | while ( $row = @mysqli_fetch_object( $this->result ) ) { 337 | $this->last_result[$num_rows] = $row; 338 | $num_rows++; 339 | } 340 | } elseif ( is_resource( $this->result ) ) { 341 | while ( $row = @mysql_fetch_object( $this->result ) ) { 342 | $this->last_result[$num_rows] = $row; 343 | $num_rows++; 344 | } 345 | } 346 | 347 | // Log number of rows the query returned 348 | // and return number of rows selected 349 | $this->num_rows = $num_rows; 350 | $return_val = $num_rows; 351 | } 352 | 353 | return $return_val; 354 | } 355 | 356 | public function get_results( $query = null, $output = OBJECT ) { 357 | 358 | if ( $query ) { 359 | $this->query($query); 360 | } else { 361 | return null; 362 | } 363 | 364 | $new_array = array(); 365 | if ( $output == OBJECT ) { 366 | // Return an integer-keyed array of row objects 367 | return $this->last_result; 368 | } elseif ( $output == OBJECT_K ) { 369 | // Return an array of row objects with keys from column 1 370 | // (Duplicates are discarded) 371 | foreach ( $this->last_result as $row ) { 372 | $var_by_ref = get_object_vars( $row ); 373 | $key = array_shift( $var_by_ref ); 374 | if ( ! isset( $new_array[ $key ] ) ) 375 | $new_array[ $key ] = $row; 376 | } 377 | return $new_array; 378 | } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { 379 | // Return an integer-keyed array of... 380 | if ( $this->last_result ) { 381 | foreach( (array) $this->last_result as $row ) { 382 | if ( $output == ARRAY_N ) { 383 | // ...integer-keyed row arrays 384 | $new_array[] = array_values( get_object_vars( $row ) ); 385 | } else { 386 | // ...column name-keyed row arrays 387 | $new_array[] = get_object_vars( $row ); 388 | } 389 | } 390 | } 391 | return $new_array; 392 | } elseif ( strtoupper( $output ) === OBJECT ) { 393 | // Back compat for OBJECT being previously case insensitive. 394 | return $this->last_result; 395 | } 396 | return null; 397 | } 398 | 399 | public function get_col( $query = null , $x = 0 ) { 400 | 401 | if ( $query ) { 402 | $this->query( $query ); 403 | } 404 | 405 | $new_array = array(); 406 | // Extract the column values 407 | for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 408 | $new_array[$i] = $this->get_var( null, $x, $i ); 409 | } 410 | return $new_array; 411 | } 412 | 413 | public function get_row( $query = null, $output = OBJECT, $y = 0 ) { 414 | if ( $query ) { 415 | $this->query( $query ); 416 | } else { 417 | return null; 418 | } 419 | 420 | if ( !isset( $this->last_result[$y] ) ) 421 | return null; 422 | 423 | if ( $output == OBJECT ) { 424 | return $this->last_result[$y] ? $this->last_result[$y] : null; 425 | } elseif ( $output == ARRAY_A ) { 426 | return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; 427 | } elseif ( $output == ARRAY_N ) { 428 | return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; 429 | } elseif ( strtoupper( $output ) === OBJECT ) { 430 | // Back compat for OBJECT being previously case insensitive. 431 | return $this->last_result[$y] ? $this->last_result[$y] : null; 432 | } else { 433 | $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" ); 434 | } 435 | } 436 | 437 | public function get_var( $query = null, $x = 0, $y = 0 ) { 438 | 439 | if ( $query ) { 440 | $this->query( $query ); 441 | } 442 | 443 | // Extract var out of cached results based x,y vals 444 | if ( !empty( $this->last_result[$y] ) ) { 445 | $values = array_values( get_object_vars( $this->last_result[$y] ) ); 446 | } 447 | 448 | // If there is a value return it else return null 449 | return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null; 450 | } 451 | function dump_result($query, $output = OBJECT) { 452 | // echo "\n\t\t-=- DUMP -=-\n"; 453 | $result = $this->get_results($query, $output); 454 | $size = sizeof($result); 455 | for( $i = 0 ; $i < $size; $i++){ 456 | $row = $result[$i]; 457 | $res_str = ""; 458 | $num_cols = sizeof($row); 459 | for ($j = 0 ; $j < $num_cols; $j++){ 460 | $res_str .= ($row[$j] . "\t"); 461 | } 462 | $res_str .= "\n"; 463 | // echo $res_str; 464 | } 465 | } 466 | 467 | } 468 | 469 | function print_row($row) { 470 | for($i=0; $iget_results( sprintf("SELECT $db_obj->table_one.* FROM $db_obj->table_one WHERE col1 IN (%s)", join(",", $ids))); 484 | } 485 | // TODO Iterate through results 486 | // also can do different things here like 487 | // parsing the result or updating something 488 | } 489 | 490 | function second_query($db_obj) { 491 | /* simulates all of select option stuff from WP queries 492 | table1 - col2 = options->option_name 493 | table1 - col3 = options->option_value 494 | table1 - col2 = options->autoload 495 | */ 496 | 497 | //SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes' 498 | //option.php @158 499 | $query = "SELECT col2, col3 FROM $db_obj->table_one WHERE col4 = 'yes'"; 500 | $db_obj->dump_result($query, ARRAY_N); 501 | if ( !$something_db = $db_obj->get_results( "SELECT col2, col3 FROM $db_obj->table_one WHERE col4 = 'yes'" ) ) 502 | $something_db = $db_obj->get_results( "SELECT col2, col3 FROM $db_obj->table_one" ); 503 | } 504 | 505 | function select_simple_WHERE($db_obj, $select_this="col3", $col_name="col2", $name="\"something\"") { 506 | /* All select option_value from options ... 507 | option.php @25 508 | */ 509 | $row = $db_obj->get_row("SELECT col3 FROM $db_obj->table_one WHERE $col_name = $name LIMIT 1", ARRAY_N); 510 | // print_row($row); 511 | if ($row) 512 | return true; 513 | return false; 514 | } 515 | 516 | function select_INNER_JOIN($db_obj) { 517 | $taxonomies = array("\"WinnieThePooh\"", "\"Mickey Mouse\"", "\"something\""); 518 | $ids = range(0, 100, 2); 519 | $first = "tr.col2 IN (" . implode(" , ",$taxonomies) . ")"; 520 | $second = "tr.col1 IN (" . implode(" , ",$ids) . ")"; 521 | $where = array( $first, $second); 522 | $where = implode( " AND ", $where ); 523 | $select_this = "t.*, tt.*"; 524 | 525 | $orderby = "ORDER BY tt.col1"; 526 | $query = "SELECT $select_this FROM $db_obj->table_two AS t INNER JOIN $db_obj->table_one AS tt ON tt.col1 = t.col1 INNER JOIN $db_obj->table_three AS tr ON tr.col1 = tt.col1 WHERE $where $orderby"; 527 | //$results = $db_obj->get_results($query); 528 | $result = $db_obj->dump_result($query, ARRAY_N); 529 | } 530 | 531 | function multiple_WHERE_CLAUSES($db_obj, $select_this="*", $order_by="ORDER BY col1") { 532 | 533 | $query = "SELECT $select_this FROM $db_obj->table_one WHERE $db_obj->table_one.col3=\"something\" AND $db_obj->table_one.col4=\"yes\" $order_by"; 534 | $result = $db_obj->dump_result($query, ARRAY_N); 535 | $row = $db_obj->get_row($query, ARRAY_N); 536 | 537 | } 538 | --------------------------------------------------------------------------------