Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/sortperf.cpython-311.pyc
�

�Ke����dZddlZddlZddlZddlZddlZddlZej��Zd�Z	d�Z
d�Zd�Zd�Z
edkre
��dSdS)	z_Sort performance test.

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

�Nc���tj�td|z��}	t	|d��}tj|��}|���td��D]O}tj
|��}|d|�}|d|�=|���|�|��~�Pn�#t$r�tj	��fd�t|��D��}		t	|d��}tj||��|���d}|r&	tj|��n>#t$rYn2wxYwn-#|r&	tj|��w#t$rYwwxYwwxYwn)#t$r}t!d|d|��Yd}~nd}~wwxYwYnwxYwt#|��|ksJ�|S)	z+Return a list of n random floats in [0, 1).zrr%06d�rb�
Nc�$��g|]}�����
S�r)�.0�i�rs  ��7/usr/local/apps/python3/lib/python3.11/test/sortperf.py�
<listcomp>zrandfloats.<locals>.<listcomp>s���(�(�(�!�!�!�#�#�(�(�(��wbzcan'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�
��L�L�N�N�N��M�M�$������
	��+�/�/�/��M��(�(�(�(�u�Q�x�x�(�(�(��
	/�

��"�d�^�^����V�R�(�(�(����
�
�
�������	�"�
�
�
�
��"������������2����	�"�
�
�
�
��"����������������
�	/�	/�	/��-��S�#�.�.�.�.�.�.�.�.�����	/������/����8�v�;�;�!������Ms��C�1F4�6;E�1F�4E	�F�	
E�F�E�F�F�E3�2F�3
F	�=F�?F	�F�F�F4�
F.�F)�$F4�)F.�.F4�3F4c�B�tj���dS�N)�sys�stdout�flushrr
rr-r-8s���J�������r
c���tj��}|���tj��}td||z
zd���t	��dS)Nz%6.2f� ��end)�time�perf_counter�sortr r-)�L�t0�t1s   r�doitr8;sT��	
�	�	�	�B��F�F�H�H�H�	
�	�	�	�B�	�'�R��U�
��%�%�%�%�	�G�G�G�G�Gr
c�F�td�dD����}ddt|��zz}t|d|zz��|D�]Y}d|z}t|��}td||fzd�	��t	��t|��|���t|��t|��td
��D]A}tj	|��}tj	|��}||||c||<||<�Bt|��|dkrd�td��D��|d
d�<t|��t|dz��D]*}tj��|tj	|��<�+t|��|dkr+|dd�=||dzz}ttd�|����}t|��~tttdg|z����}t|��~|dz}	tt|	dz
dd����}|�
t|	����ttt|����}t|��t����[dS)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|]}|dz��S)r4r)r�chs  rrztabulate.<locals>.<listcomp>Us��6�6�6�2�2��;�6�6�6r
z	*\/3+%~=!z%2s %7sz %6s)r	z2**i�z%2d %7dr/r0�rc�4�g|]}tj����Sr)r)r�dummys  rrztabulate.<locals>.<listcomp>ks��>�>�>�5�v�}���>�>�>r
i����N�d�c�
�|Sr*r)�xs r�<lambda>ztabulate.<locals>.<lambda>ys
��Q�B�3�r
g�����)�tupler!r r(r-r8rrrr�list�map�absr�float)
r
�cases�fmtr	r"r5r?�i1�i2�halfs
          r�tabulaterQBs���&
�6�6��6�6�6�7�7�E��v�c�%�j�j�(�(�C�	�#���&�
'�(�(�(�
�4�4��
��F���q�M�M��
�i�1�a�&� �c�*�*�*�*�
�����Q����	�	�	�����Q�����Q�����1�X�X�	(�	(�E��!�!�$�$�B��!�!�$�$�B��R�5�!�B�%�L�A�b�E�1�R�5�5��Q����
��7�7�>�>�E�"�I�I�>�>�>�A�c�d�d�G��Q�����1��8�_�_�	5�	5�E�%+�]�_�_�A�f��q�!�!�"�"��Q����
�q�5�5��!�"�"���Q�!�V��A��S����*�*�+�+�A��Q����
�
��S�4�&�1�*�%�%�&�&���Q����
�
�A�v����t�a�x��R�(�(�)�)��	����t������
��U�A�������Q����
�����i4�4r
c���d}d}tjdd�r�ttjd��x}}tjdd�ruttjd��}tjdd�rBd}tjdd�D]}d|zt|��z}�t	j|��t
||dz��}t|��dS)z�Main 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<NrEr=i�
)r+�argv�int�hashr�seedrrQ)�k1�k2rC�ar
s     r�mainr\�s���
�B�	�B�
�x����|���c�h�q�k�"�"�"��R��8�A�B�B�<�	��S�X�a�[�!�!�B��x����|�
�����!�"�"��,�,�A���	�D��G�G�+�A�A���A����
�b�"�Q�$���A��Q�K�K�K�K�Kr
�__main__)�__doc__r+r2rr�tempfiler�
gettempdirrr(r-r8rQr\�__name__rr
r�<module>rbs������
�
�
�����
�
�
�
���������	�	�	�	��X�����%�%�%�N������J�J�J�X���4�z����D�F�F�F�F�F��r