js/src/tests/ecma_3/RegExp/regress-85721.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-85721.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,243 @@
     1.4 +// |reftest| random -- bogus perf test (bug 467263)
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 + *
    1.12 + * Date:    14 Feb 2002
    1.13 + * SUMMARY: Performance: Regexp performance degraded from 4.7
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=85721
    1.15 + *
    1.16 + * Adjust this testcase if necessary. The FAST constant defines
    1.17 + * an upper bound in milliseconds for any execution to take.
    1.18 + *
    1.19 + */
    1.20 +//-----------------------------------------------------------------------------
    1.21 +var BUGNUMBER = 85721;
    1.22 +var summary = 'Performance: execution of regular expression';
    1.23 +var FAST = 100; // execution should be 100 ms or less to pass the test
    1.24 +var MSG_FAST = 'Execution took less than ' + FAST + ' ms';
    1.25 +var MSG_SLOW = 'Execution took ';
    1.26 +var MSG_MS = ' ms';
    1.27 +var str = '';
    1.28 +var re = '';
    1.29 +var status = '';
    1.30 +var actual = '';
    1.31 +var expect= '';
    1.32 +
    1.33 +printBugNumber(BUGNUMBER);
    1.34 +printStatus (summary);
    1.35 +
    1.36 +
    1.37 +function elapsedTime(startTime)
    1.38 +{
    1.39 +  return new Date() - startTime;
    1.40 +}
    1.41 +
    1.42 +
    1.43 +function isThisFast(ms)
    1.44 +{
    1.45 +  if (ms <= FAST)
    1.46 +    return MSG_FAST;
    1.47 +  return MSG_SLOW + ms + MSG_MS;
    1.48 +}
    1.49 +
    1.50 +
    1.51 +
    1.52 +/*
    1.53 + * The first regexp. We'll test for performance (Section 1) and accuracy (Section 2).
    1.54 + */
    1.55 +str='<sql:connection id="conn1"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>';
    1.56 +re = /<sql:connection id="([^\r\n]*?)">\s*<sql:url>\s*([^\r\n]*?)\s*<\/sql:url>\s*<sql:driver>\s*([^\r\n]*?)\s*<\/sql:driver>\s*(\s*<sql:userId>\s*([^\r\n]*?)\s*<\/sql:userId>\s*)?\s*(\s*<sql:password>\s*([^\r\n]*?)\s*<\/sql:password>\s*)?\s*<\/sql:connection>/;
    1.57 +expect = Array("<sql:connection id=\"conn1\"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>","conn1","www.m.com","drive.class","<sql:userId>foo</sql:userId> ","foo","<sql:password>goo</sql:password> ","goo");
    1.58 +
    1.59 +/*
    1.60 + *  Check performance -
    1.61 + */
    1.62 +status = inSection(1);
    1.63 +var start = new Date();
    1.64 +var result = re.exec(str);
    1.65 +actual = elapsedTime(start);
    1.66 +reportCompare(isThisFast(FAST), isThisFast(actual), status);
    1.67 +
    1.68 +/*
    1.69 + *  Check accuracy -
    1.70 + */
    1.71 +status = inSection(2);
    1.72 +testRegExp([status], [re], [str], [result], [expect]);
    1.73 +
    1.74 +
    1.75 +
    1.76 +/*
    1.77 + * The second regexp (HUGE!). We'll test for performance (Section 3) and accuracy (Section 4).
    1.78 + * It comes from the O'Reilly book "Mastering Regular Expressions" by Jeffrey Friedl, Appendix B
    1.79 + */
    1.80 +
    1.81 +//# Some things for avoiding backslashitis later on.
    1.82 +$esc        = '\\\\';     
    1.83 +$Period      = '\.';
    1.84 +$space      = '\040';              $tab         = '\t';
    1.85 +$OpenBR     = '\\[';               $CloseBR     = '\\]';
    1.86 +$OpenParen  = '\\(';               $CloseParen  = '\\)';
    1.87 +$NonASCII   = '\x80-\xff';         $ctrl        = '\000-\037';
    1.88 +$CRlist     = '\n\015';  //# note: this should really be only \015.
    1.89 +// Items 19, 20, 21
    1.90 +$qtext = '[^' + $esc + $NonASCII + $CRlist + '\"]';						  // # for within "..."
    1.91 +$dtext = '[^' + $esc + $NonASCII + $CRlist + $OpenBR + $CloseBR + ']';    // # for within [...]
    1.92 +$quoted_pair = $esc + '[^' + $NonASCII + ']';							  // # an escaped character
    1.93 +
    1.94 +//##############################################################################
    1.95 +//# Items 22 and 23, comment.
    1.96 +//# Impossible to do properly with a regex, I make do by allowing at most one level of nesting.
    1.97 +$ctext   =  '[^' + $esc + $NonASCII + $CRlist + '()]';
    1.98 +
    1.99 +//# $Cnested matches one non-nested comment.
   1.100 +//# It is unrolled, with normal of $ctext, special of $quoted_pair.
   1.101 +$Cnested =
   1.102 +  $OpenParen +                                 // #  (
   1.103 +  $ctext + '*' +                            // #     normal*
   1.104 +  '(?:' + $quoted_pair + $ctext + '*)*' +   // #     (special normal*)*
   1.105 +  $CloseParen;                                 // #                       )
   1.106 +
   1.107 +
   1.108 +//# $comment allows one level of nested parentheses
   1.109 +//# It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested)
   1.110 +$comment =
   1.111 +  $OpenParen +                                           // #  (
   1.112 +  $ctext + '*' +                                     // #     normal*
   1.113 +  '(?:' +                                            // #       (
   1.114 +  '(?:' + $quoted_pair + '|' + $Cnested + ')' +   // #         special
   1.115 +  $ctext + '*' +                                 // #         normal*
   1.116 +  ')*' +                                             // #            )*
   1.117 +  $CloseParen;                                           // #                )
   1.118 +
   1.119 +
   1.120 +//##############################################################################
   1.121 +//# $X is optional whitespace/comments.
   1.122 +$X =
   1.123 +  '[' + $space + $tab + ']*' +					       // # Nab whitespace.
   1.124 +  '(?:' + $comment + '[' + $space + $tab + ']*)*';    // # If comment found, allow more spaces.
   1.125 +
   1.126 +
   1.127 +//# Item 10: atom
   1.128 +$atom_char   = '[^(' + $space + '<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $ctrl + $NonASCII + ']';
   1.129 +$atom =
   1.130 +  $atom_char + '+' +            // # some number of atom characters...
   1.131 +  '(?!' + $atom_char + ')';     // # ..not followed by something that could be part of an atom
   1.132 +
   1.133 +// # Item 11: doublequoted string, unrolled.
   1.134 +$quoted_str =
   1.135 +  '\"' +                                         // # "
   1.136 +  $qtext + '*' +                              // #   normal
   1.137 +  '(?:' + $quoted_pair + $qtext + '*)*' +     // #   ( special normal* )*
   1.138 +  '\"';                                          // # "
   1.139 +
   1.140 +//# Item 7: word is an atom or quoted string
   1.141 +$word =
   1.142 +  '(?:' +
   1.143 +  $atom +                // # Atom
   1.144 +  '|' +                  //     #  or
   1.145 +  $quoted_str +          // # Quoted string
   1.146 +  ')'
   1.147 +
   1.148 +//# Item 12: domain-ref is just an atom
   1.149 +  $domain_ref  = $atom;
   1.150 +
   1.151 +//# Item 13: domain-literal is like a quoted string, but [...] instead of  "..."
   1.152 +$domain_lit  =
   1.153 +  $OpenBR +								   	     // # [
   1.154 +  '(?:' + $dtext + '|' + $quoted_pair + ')*' +     // #    stuff
   1.155 +  $CloseBR;                                        // #           ]
   1.156 +
   1.157 +// # Item 9: sub-domain is a domain-ref or domain-literal
   1.158 +$sub_domain  =
   1.159 +  '(?:' +
   1.160 +  $domain_ref +
   1.161 +  '|' +
   1.162 +  $domain_lit +
   1.163 +  ')' +
   1.164 +  $X;                 // # optional trailing comments
   1.165 +
   1.166 +// # Item 6: domain is a list of subdomains separated by dots.
   1.167 +$domain =
   1.168 +  $sub_domain +
   1.169 +  '(?:' +
   1.170 +  $Period + $X + $sub_domain +
   1.171 +  ')*';
   1.172 +
   1.173 +//# Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon.
   1.174 +$route =
   1.175 +  '\@' + $X + $domain +
   1.176 +  '(?:,' + $X + '\@' + $X + $domain + ')*' +  // # additional domains
   1.177 +  ':' +
   1.178 +  $X;					// # optional trailing comments
   1.179 +
   1.180 +//# Item 6: local-part is a bunch of $word separated by periods
   1.181 +$local_part =
   1.182 +  $word + $X
   1.183 +  '(?:' +
   1.184 +  $Period + $X + $word + $X +		// # additional words
   1.185 +  ')*';
   1.186 +
   1.187 +// # Item 2: addr-spec is local@domain
   1.188 +$addr_spec  =
   1.189 +  $local_part + '\@' + $X + $domain;
   1.190 +
   1.191 +//# Item 4: route-addr is <route? addr-spec>
   1.192 +$route_addr =
   1.193 +  '<' + $X +                     // # <
   1.194 +  '(?:' + $route + ')?' +     // #       optional route
   1.195 +  $addr_spec +                // #       address spec
   1.196 +  '>';                           // #                 >
   1.197 +
   1.198 +//# Item 3: phrase........
   1.199 +$phrase_ctrl = '\000-\010\012-\037'; // # like ctrl, but without tab
   1.200 +
   1.201 +//# Like atom-char, but without listing space, and uses phrase_ctrl.
   1.202 +//# Since the class is negated, this matches the same as atom-char plus space and tab
   1.203 +$phrase_char =
   1.204 +  '[^()<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $NonASCII + $phrase_ctrl + ']';
   1.205 +
   1.206 +// # We've worked it so that $word, $comment, and $quoted_str to not consume trailing $X
   1.207 +// # because we take care of it manually.
   1.208 +$phrase =
   1.209 +  $word +                                                  // # leading word
   1.210 +  $phrase_char + '*' +                                     // # "normal" atoms and/or spaces
   1.211 +  '(?:' +
   1.212 +  '(?:' + $comment + '|' + $quoted_str + ')' +          // # "special" comment or quoted string
   1.213 +  $phrase_char + '*' +                                  // #  more "normal"
   1.214 +  ')*';
   1.215 +
   1.216 +// ## Item #1: mailbox is an addr_spec or a phrase/route_addr
   1.217 +$mailbox =
   1.218 +  $X +                                // # optional leading comment
   1.219 +  '(?:' +
   1.220 +  $phrase + $route_addr +     // # name and address
   1.221 +  '|' +                       //     #  or
   1.222 +  $addr_spec +                // # address
   1.223 +  ')';
   1.224 +
   1.225 +
   1.226 +//###########################################################################
   1.227 +
   1.228 +
   1.229 +re = new RegExp($mailbox, "g");
   1.230 +str = 'Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>';
   1.231 +expect = Array('Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>');
   1.232 +
   1.233 +/*
   1.234 + *  Check performance -
   1.235 + */
   1.236 +status = inSection(3);
   1.237 +var start = new Date();
   1.238 +var result = re.exec(str);
   1.239 +actual = elapsedTime(start);
   1.240 +reportCompare(isThisFast(FAST), isThisFast(actual), status);
   1.241 +
   1.242 +/*
   1.243 + *  Check accuracy -
   1.244 + */
   1.245 +status = inSection(4);
   1.246 +testRegExp([status], [re], [str], [result], [expect]);

mercurial