| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | function c( $text ) {}
|
|---|
| 4 |
|
|---|
| 5 | /*
|
|---|
| 6 | */
|
|---|
| 7 | function bw_get_elapsed( $tods ) {
|
|---|
| 8 | $tode = microtime( );
|
|---|
| 9 | //e( $tode );
|
|---|
| 10 | list( $su, $ss ) = explode(" ", $tods );
|
|---|
| 11 | list( $eu, $es ) = explode(" ", $tode );
|
|---|
| 12 | $elapsedsec = $es - $ss;
|
|---|
| 13 | $elapsedu = $eu - $su;
|
|---|
| 14 |
|
|---|
| 15 | $elapsed = $elapsedsec + $elapsedu;
|
|---|
| 16 |
|
|---|
| 17 | //e( $elapsedsec );
|
|---|
| 18 | //e( $elapsedu );
|
|---|
| 19 | //e( $elapsed );
|
|---|
| 20 | return( $elapsed );
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | function oik_error_reporting() {
|
|---|
| 25 |
|
|---|
| 26 | //error_reporting( E_ALL );
|
|---|
| 27 | error_reporting( E_ALL & ~E_DEPRECATED );
|
|---|
| 28 | @ini_set('display_errors',1);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | if ( !function_exists( "add_filter" ) ) {
|
|---|
| 32 | function add_filter( $arg1=null, $arg2=null ) {}
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | function bw_average( $elapsed, $count ) {
|
|---|
| 37 | if ( $count ) {
|
|---|
| 38 | $average = $elapsed / $count ;
|
|---|
| 39 | $av = sprintf( "%1.6F", $average );
|
|---|
| 40 | c( $average );
|
|---|
| 41 | c( $av );
|
|---|
| 42 | } else {
|
|---|
| 43 | $av = $elapsed;
|
|---|
| 44 | }
|
|---|
| 45 | return( $av );
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * Include the original shortcodes.php from WordPress
|
|---|
| 50 | * THE fixed code is in get_shortcode_17567
|
|---|
| 51 | */
|
|---|
| 52 |
|
|---|
| 53 | require_once "shortcodes.php" ;
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | function dofor( $func = 'test_bag', $limit=1000 ) {
|
|---|
| 58 | global $p, $dome, $count ;
|
|---|
| 59 | $tods = microtime();
|
|---|
| 60 |
|
|---|
| 61 | for ( $i = 1; $i <= $limit; $i++ )
|
|---|
| 62 | $func();
|
|---|
| 63 | $elapsed = sprintf( "%2.6f", bw_get_elapsed( $tods ) );
|
|---|
| 64 | $average = sprintf( "%2.6f", bw_average( $elapsed, $limit ));
|
|---|
| 65 | //$p( "$func Ela: $elapsed Ave: $average Lim: $limit " . substr( $dome, 0, 40) );
|
|---|
| 66 | $codes = $count * 2;
|
|---|
| 67 | $p( "$func,$elapsed,$average,$limit,$codes,". substr( $dome, 0, 41) );
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | function wpsc( $atts =null ) {
|
|---|
| 72 | return( "wp" );
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | function test_data( $repeat, $text, $shortcode=null, $scount=0 ) {
|
|---|
| 77 | $string = "$text ";
|
|---|
| 78 | if ( $shortcode ) {
|
|---|
| 79 | for ( $count = 1; $count<= $scount; $count++ ) {
|
|---|
| 80 | $string .= "[$shortcode-$count] [$shortcode$count] ";
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | $string = str_repeat( $string, $repeat );
|
|---|
| 84 | $totscs = $repeat * $scount * 2;
|
|---|
| 85 | $result = ",$repeat,$scount,$string";
|
|---|
| 86 | $result = strlen( $result ) . $result;
|
|---|
| 87 | return $result;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | function original() {
|
|---|
| 94 | global $dome;
|
|---|
| 95 | do_shortcode( $dome );
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | $p = "q";
|
|---|
| 101 | function q( $text ) {
|
|---|
| 102 | echo "$text\n" ;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | function do_hmo17567($content) {
|
|---|
| 107 | if ( false === strpos( $content, "[" ) ) {
|
|---|
| 108 | //gobang();
|
|---|
| 109 | return $content;
|
|---|
| 110 | }
|
|---|
| 111 | global $shortcode_tags;
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | if (empty($shortcode_tags) || !is_array($shortcode_tags))
|
|---|
| 115 | return $content;
|
|---|
| 116 |
|
|---|
| 117 | $pattern = get_shortcode_regex();
|
|---|
| 118 | return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | function do_hmf17567($content) {
|
|---|
| 124 |
|
|---|
| 125 | if ( false === strpos( $content, "[" ) )
|
|---|
| 126 | return $content;
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | global $shortcode_tags;
|
|---|
| 130 | if (empty($shortcode_tags) || !is_array($shortcode_tags))
|
|---|
| 131 | return $content;
|
|---|
| 132 |
|
|---|
| 133 | $pattern = get_shortcode_17567();
|
|---|
| 134 | return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | function do_fix17567( $content ) {
|
|---|
| 139 | global $shortcode_tags;
|
|---|
| 140 |
|
|---|
| 141 | if (empty($shortcode_tags) || !is_array($shortcode_tags))
|
|---|
| 142 | return $content;
|
|---|
| 143 | $pattern = get_shortcode_17567();
|
|---|
| 144 | return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | function get_shortcode_17567() {
|
|---|
| 149 | global $shortcode_tags;
|
|---|
| 150 | $tagnames = array_keys($shortcode_tags);
|
|---|
| 151 | $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
|
|---|
| 152 |
|
|---|
| 153 | // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
|
|---|
| 154 |
|
|---|
| 155 | // . '\\b' // Word boundary
|
|---|
| 156 | return
|
|---|
| 157 | '\\[' // Opening bracket
|
|---|
| 158 | . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
|
|---|
| 159 | . "($tagregexp)" // 2: Shortcode name
|
|---|
| 160 | . '(?![\\w-])' // Word boundary
|
|---|
| 161 | . '(' // 3: Unroll the loop: Inside the opening shortcode tag
|
|---|
| 162 | . '[^\\]\\/]*' // Not a closing bracket or forward slash
|
|---|
| 163 | . '(?:'
|
|---|
| 164 | . '\\/(?!\\])' // A forward slash not followed by a closing bracket
|
|---|
| 165 | . '[^\\]\\/]*' // Not a closing bracket or forward slash
|
|---|
| 166 | . ')*?'
|
|---|
| 167 | . ')'
|
|---|
| 168 | . '(?:'
|
|---|
| 169 | . '(\\/)' // 4: Self closing tag ...
|
|---|
| 170 | . '\\]' // ... and closing bracket
|
|---|
| 171 | . '|'
|
|---|
| 172 | . '\\]' // Closing bracket
|
|---|
| 173 | . '(?:'
|
|---|
| 174 | . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
|
|---|
| 175 | . '[^\\[]*+' // Not an opening bracket
|
|---|
| 176 | . '(?:'
|
|---|
| 177 | . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
|
|---|
| 178 | . '[^\\[]*+' // Not an opening bracket
|
|---|
| 179 | . ')*+'
|
|---|
| 180 | . ')'
|
|---|
| 181 | . '\\[\\/\\2\\]' // Closing shortcode tag
|
|---|
| 182 | . ')?'
|
|---|
| 183 | . ')'
|
|---|
| 184 | . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | function fix17567() {
|
|---|
| 191 | global $dome;
|
|---|
| 192 | do_fix17567( $dome );
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | function hmo17567() {
|
|---|
| 196 | global $dome;
|
|---|
| 197 | do_hmo17567( $dome );
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | function hmf17567() {
|
|---|
| 201 | global $dome;
|
|---|
| 202 | do_hmf17567( $dome );
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 | oik_error_reporting();
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | $content = array();
|
|---|
| 210 | $content[] = test_data( 1, "no shortcodes in the text." );
|
|---|
| 211 | $content[] = test_data( 10, "no shortcodes in the text. " );
|
|---|
| 212 | $content[] = test_data( 100, "no shortcodes in the text. " );
|
|---|
| 213 | $content[] = test_data( 1000, "no shortcodes in the text. " );
|
|---|
| 214 | $content[] = test_data( 2000, "code is poetry " );
|
|---|
| 215 |
|
|---|
| 216 | $content[] = test_data( 1, "one shortcode", "wp", 1 );
|
|---|
| 217 | $content[] = test_data( 1, "two shortcodes", "wp", 2 );
|
|---|
| 218 | $content[] = test_data( 1, "three shorcodes", "wp", 3 );
|
|---|
| 219 | $content[] = test_data( 100, "many [wp]'s " );
|
|---|
| 220 | $content[] = test_data( 100, "many [[wp]]'s " );
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | $content[] = test_data( 1, "5 shortcodes in the text", "wp", 5 );
|
|---|
| 224 | $content[] = test_data( 10, "10x5 shortcodes in the text", "wp", 5 );
|
|---|
| 225 | $content[] = test_data( 5, "5x10 shortcodes in the text", "wp", 10 );
|
|---|
| 226 | //$content[] = test_data( 100, "100x10 shortcodes in the text", "wp", 10 );
|
|---|
| 227 | $content[] = test_data( 1, "100 shortcodes in the text", "wp", 100 );
|
|---|
| 228 | //$content[] = test_data( 10, "10x100 shortcodes in the text", "wp", 100 );
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 | add_shortcode( "wpdo", "wpsc" );
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | for ( $count = 0; $count <= 100; $count += 10 ) {
|
|---|
| 238 | add_shortcode( "wp-$count", "wpsc" );
|
|---|
| 239 | add_shortcode( "wp$count", "wpsc" );
|
|---|
| 240 | foreach ( $content as $dome ) {
|
|---|
| 241 |
|
|---|
| 242 | //echo $dome . PHP_EOL;
|
|---|
| 243 |
|
|---|
| 244 | dofor( "original", 1000 );
|
|---|
| 245 | dofor( "fix17567", 1000 );
|
|---|
| 246 | dofor( "hmo17567", 1000 );
|
|---|
| 247 | dofor( "hmf17567", 1000);
|
|---|
| 248 | //q(PHP_EOL);
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|