
    ;e                         d Z ddlZddlZddlZddlZddlZddlZ ej                    Zd Z	d Z
d Zd Zd Zedk    r e             dS dS )	z_Sort performance test.

See main() for command line syntax.
See tabulate() for output format.

    Nc                    t           j                            t          d| z            }	 t	          |d          }t          j        |          }|                                 t          d          D ]O}t          j
        |           }|d|         }|d|= |                                 |                    |           ~Pn# t          $ r t          j	        fdt          |           D             }	 	 t	          |d          }t          j        ||           |                                 d}|r&	 t          j        |           n># t          $ r Y n2w xY wn-# |r&	 t          j        |           w # t          $ r Y w w xY ww xY wn)# t          $ r}t!          d|d|           Y d}~nd}~ww xY wY nw xY wt#          |          | k    sJ |S )	z+Return a list of n random floats in [0, 1).zrr%06drb
   Nc                 $    g | ]}             S  r   ).0irs     $/usr/lib/python3.11/test/sortperf.py
<listcomp>zrandfloats.<locals>.<listcomp>   s    (((!!!##(((    wbzcan't write:)ospathjointdopenmarshalloadcloserangerandom	randrangereverseextendOSErrordumpunlinkprintlen)nfnfpresultr	   tempmsgr
   s          @r   
randfloatsr(      s   
 
b(Q,	'	'B"d^^& b!!



r 	 	A ##A"1":Drr
LLNNNMM$	+  / / /M((((uQxx(((	/
"d^^VR(((


 	""   2 	""   
  	/ 	/ 	/-S#........	//8 v;;!Ms   C 1F46;E1F4E	F	
EFEFFE32F3
F 	=F?F 	 FFF4
F.F)$F4)F..F43F4c                  B    t           j                                         d S N)sysstdoutflushr   r   r   r-   r-   8   s    Jr   c                     t          j                    }|                                  t          j                    }t          d||z
  z  d           t	                       d S )Nz%6.2f end)timeperf_countersortr    r-   )Lt0t1s      r   doitr8   ;   sT    				BFFHHH				B	'RU
%%%%	GGGGGr   c                 F   t          d dD                       }ddt          |          z  z   }t          |d|z   z             | D ]Y}d|z  }t          |          }t          d||fz  d	           t	                       t          |           |                                 t          |           t          |           t          d
          D ]A}t          j	        |          }t          j	        |          }||         ||         c||<   ||<   Bt          |           |dk    rd t          d          D             |dd<   t          |           t          |dz            D ]*}t          j                    |t          j	        |          <   +t          |           |dk    r+|dd= ||dz  z  }t          t          d |                    }t          |           ~t          t          t          dg|z                      }t          |           ~|dz  }	t          t          |	dz
  dd                    }|                    t          |	                     t          t          t          |                    }t          |           t                       [dS )a:  Tabulate sort speed for lists of various sizes.

    The sizes are 2**i for i in r (the argument, a list).

    The output displays i, 2**i, and the time to sort arrays of 2**i
    floating point numbers with the following properties:

    *sort: random data
    \sort: descending data
    /sort: ascending data
    3sort: ascending, then 3 random exchanges
    +sort: ascending, then 10 random at the end
    %sort: ascending, then randomly replace 1% of the elements w/ random values
    ~sort: many duplicates
    =sort: all equal
    !sort: worst case scenario

    c                     g | ]}|d z   S )r4   r   )r   chs     r   r   ztabulate.<locals>.<listcomp>U   s    66622;666r   z	*\/3+%~=!z%2s %7sz %6s)r	   z2**i   z%2d %7dr/   r0      r   c                 4    g | ]}t          j                     S r   )r   )r   dummys     r   r   ztabulate.<locals>.<listcomp>k   s    >>>5v}>>>r   iNd      c                 
    |   S r*   r   )xs    r   <lambda>ztabulate.<locals>.<lambda>y   s
    QB3 r   g         )tupler!   r    r(   r-   r8   r   r   r   r   listmapabsr   float)
r
   casesfmtr	   r"   r5   r?   i1i2halfs
             r   tabulaterQ   B   s   & 6666677Evc%jj((C	#&
'((( 4 4FqMMi1a& c****Q			QQ 1XX 	( 	(E!!$$B!!$$BR5!B%LAbE1R55Q 77>>E"II>>>AcddGQ 18__ 	5 	5E%+]__Afq!!""Q q55!""Q!VA S**++AQ S4&1*%%&&Q
 AvtaxR(())	t UAQi4 4r   c                     d} d}t           j        dd         rt          t           j        d                   x} }t           j        dd         rut          t           j        d                   }t           j        dd         rBd}t           j        dd         D ]}d|z  t          |          z   }t	          j        |           t          | |dz             }t          |           dS )zMain program when invoked as a script.

    One argument: tabulate a single row.
    Two arguments: tabulate a range (inclusive).
    Extra arguments are used to seed the random generator.

          r<   NrE   r=   i )r+   argvinthashr   seedr   rQ   )k1k2rC   ar
   s        r   mainr\      s     
B	B
x| chqk"""R8ABB< 	SXa[!!Bx| !"" , ,A	DGG+AAAb"Q$AQKKKKKr   __main__)__doc__r+   r2   r   r   tempfiler   
gettempdirr   r(   r-   r8   rQ   r\   __name__r   r   r   <module>rb      s     


     				X% % %N    J J JX  4 zDFFFFF r   