Make WordPress Core


Ignore:
Timestamp:
10/02/2015 04:25:40 AM (11 years ago)
Author:
wonderboymusic
Message:

Shortcodes/Formatting: Add PCRE Performance Testing

  • Move pattern from wptexturize() into a separate function.
  • Move pattern from wp_html_split() into a separate function.
  • Beautify code for wp_html_split().
  • Remove unnecessary instances of /s modifier in patterns that don't use dots.
  • Add tests/phpunit/data/formatting/whole-posts.php for testing larger strings.
  • Add function benchmark_pcre_backtracking().
  • Add tests for wp_html_split().
  • Add tests for wptexturize().
  • Add tests for get_shortcode_regex().

Props miqrogroove.
Fixes #34121.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r34747 r34761  
    20492049                );
    20502050        }
     2051
     2052        /**
     2053         * Automated performance testing of the main regex.
     2054         *
     2055         * @dataProvider data_whole_posts
     2056         */
     2057        function test_pcre_performance( $input ) {
     2058                global $shortcode_tags;
     2059
     2060                // With Shortcodes Disabled
     2061                $regex = _get_wptexturize_split_regex( );
     2062                $result = benchmark_pcre_backtracking( $regex, $input, 'split' );
     2063                $this->assertLessThan( 200, $result );
     2064
     2065                // With Shortcodes Enabled
     2066                $shortcode_regex = _get_wptexturize_shortcode_regex( array_keys( $shortcode_tags ) );
     2067                $regex = _get_wptexturize_split_regex( $shortcode_regex );
     2068                $result = benchmark_pcre_backtracking( $regex, $input, 'split' );
     2069                return $this->assertLessThan( 200, $result );
     2070        }
     2071
     2072        function data_whole_posts() {
     2073                require_once( DIR_TESTDATA . '/formatting/whole-posts.php' );
     2074                return data_whole_posts();
     2075        }
    20512076}
Note: See TracChangeset for help on using the changeset viewer.