Skip to content

@kovshenin /plugin.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
/**
* Plugin Name: My Plugin
* Plugin Description: http://core.trac.wordpress.org/ticket/10702
*/
class My_Plugin_Test_10702 {
public $cycles = 1000;
function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
function start() {
$this->start_time = microtime( true );
}
function stop() {
return ( microtime( true ) - $this->start_time );
}
function init() {
add_shortcode( 'foo', array( $this, 'shortcode_callback' ) );
add_shortcode( 'bar', array( $this, 'shortcode_callback' ) );
add_shortcode( 'baz', array( $this, 'shortcode_callback' ) );
// No shortcodes
$content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "no shortcodes: %f" . PHP_EOL, $this->stop() );
// Some shortcodes
$content = "Lorem [foo] ipsum dolor [bar] sit amet, consectetur adipisicing elit, [baz] sed do eiusmod tempor incididunt [foo] ut labore et dolore magna aliqua. [bar] Ut enim ad minim veniam, quis nostrud [baz] exercitation ullamco laboris nisi ut [foo arg='one'] aliquip ex ea commodo consequat. [bar arg='two'] Duis aute irure dolor in reprehenderit in voluptate velit [baz arg='three'] esse cillum dolore eu fugiat nulla pariatur. [foo arg='one'] Excepteur [/foo] sint [bar arg='two'] occaecat [/bar] cupidatat non proident, [baz arg='three'] sunt [/baz] in culpa qui officia deserunt mollit anim id est laborum.";
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "some shortcodes %f" . PHP_EOL, $this->stop() );
$content = str_repeat( $content, 10 );
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "10x shortcodes %f" . PHP_EOL, $this->stop() );
// Nested (old-style) shortcodes
$content = "Lorem [foo] ipsum dolor [bar] sit [/bar] amet [/foo], consectetur adipisicing elit, [baz] sed do [foo] eiusmod [bar] tempor [/bar] incididunt [/foo] ut labore [/baz] et dolore magna aliqua. [bar] Ut enim ad [foo] minim [/foo] veniam [/bar], quis nostrud [baz] exercitation [foo] ullamco [bar] laboris [/bar] nisi [/foo] ut [/baz] [foo arg='one'] aliquip [bar arg='two'] ex [/bar] ea commodo [/foo] consequat. [bar arg='two'] Duis aute irure dolor in reprehenderit in voluptate velit [baz arg='three'] esse cillum dolore [/baz] eu fugiat [/bar] nulla pariatur. [foo arg='one'] Excepteur [/foo] sint [bar arg='two'] occaecat [/bar] cupidatat non [foo arg='one'] proi [bar arg='two'] dent, [baz arg='three'] sunt [/baz] in [/bar] culpa qui [/foo] officia deserunt mollit anim id est laborum.";
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "nested shortcodes %f" . PHP_EOL, $this->stop() );
$content = str_repeat( $content, 10 );
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "10x nested shortcodes %f" . PHP_EOL, $this->stop() );
die();
}
function shortcode_callback( $args, $content = '', $tag ) {
$arg = @$args['arg'];
return '<' . $tag . ' arg="' . esc_attr( $arg ) . '">' . do_shortcode( $content ) . '</' . $tag . ' arg="' . esc_attr( $arg ) . '">';
}
}
new My_Plugin_Test_10702;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.