
    'it                     T    d Z ddlmZ ddlZddlmZ ddlmZ d Ze	dk(  r e        yy)a  Benchmarks for Parsimonious

Run these with ``python parsimonious/tests/benchmarks.py``. They don't run during
normal test runs because they're not tests--they don't assert anything. Also,
they're a bit slow.

These differ from the ones in test_benchmarks in that these are meant to be
compared from revision to revision of Parsimonious to make sure we're not
getting slower. test_benchmarks simply makes sure our choices among
implementation alternatives remain valid.

    )print_functionN)repeat)Grammarc                      d} dj                  | gdz        }d|z   dz   t        d      d}d}t        t        fd	d
 ||            }||z  }t	              dz  }t        d||||z  fz         y)a[  As a baseline for speed, parse some JSON.

    I have no reason to believe that JSON is a particularly representative or
    revealing grammar to test with. Also, this is a naive, unoptimized,
    incorrect grammar, so don't use it as a basis for comparison with other
    parsers. It's just meant to compare across versions of Parsimonious.

    a  {
        "id" : 1,
        "married" : true,
        "name" : "Larry Lopez",
        "sons" : null,
        "daughters" : [
          {
            "age" : 26,
            "name" : "Sandra"
            },
          {
            "age" : 25,
            "name" : "Margaret"
            },
          {
            "age" : 6,
            "name" : "Mary"
            }
          ]
        },<   z{"fathers" : [z]}a  
        value = space (string / number / object / array / true_false_null)
                space

        object = "{" members "}"
        members = (pair ("," pair)*)?
        pair = string ":" value
        array = "[" elements "]"
        elements = (value ("," value)*)?
        true_false_null = "true" / "false" / "null"

        string = space "\"" chars "\"" space
        chars = ~"[^\"]*"  # TODO implement the real thing
        number = (int frac exp) / (int exp) / (int frac) / int
        int = "-"? ((digit1to9 digits) / digit)
        frac = "." digits
        exp = e digits
        digits = digit+
        e = "e+" / "e-" / "e" / "E+" / "E-" / "E"

        digit1to9 = ~"[1-9]"
        digit = ~"[0-9]"
        space = ~"\s*"
              c                  &     j                        S N)parse)grammarjsons   N/var/www/br/venv/lib/python3.12/site-packages/parsimonious/tests/benchmarks.py<lambda>z.test_not_really_json_parsing.<locals>.<lambda>R   s    w}}T':     c                  *    t        j                         S r   )gcenable r   r   r   z.test_not_really_json_parsing.<locals>.<lambda>S   s    ryy{ r   )r   numberg      @z%Took %.3fs to parse %.1fKB: %.0fKB/s.N)joinr   minr   lenprint)	fathermore_fathersNUMBERREPEATtotal_secondsseconds_eachkbr   r   s	          @@r   test_not_really_json_parsingr#      s    F( 88VHrM*Ll*T1D  G: FF:2&,&,. /M !6)L	TV	B	
1\5757,5F5H H Ir   __main__)
__doc__
__future__r   r   timeitr   parsimonious.grammarr   r#   __name__r   r   r   <module>r*      s5    & 	  (GIT z " r   