Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python33/lib64/python3.3/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python33/lib64/python3.3/test/__pycache__/sortperf.cpython-33.pyc

�
��f�c@s�dZddlZddlZddlZddlZddlZddlZej�Zdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
ed
kr�e
�ndS(u_Sort performance test.

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

iNc s�tjjtd|�}yt|d�}Wn�tk
rtj��fdd�t|�D�}ymz3t|d�}tj	||�|j
�d}Wd|r�ytj|�Wq�tj
k
r�Yq�XnXWn8tk
r}ztd|d|�WYdd}~XnXYnwXtj|�}|j
�xZtd	�D]L}tj|�}|d|�}|d|�=|j�|j|�~q7Wt|�|ks�t�|S(
u+Return a list of n random floats in [0, 1).urr%06durbcsg|]}���qS(((u.0ui(ur(u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp>s	urandfloats.<locals>.<listcomp>uwbNucan't writeu:i
(uosupathujoinutduopenuIOErrorurandomurangeumarshaludumpucloseuNoneuunlinkuerroruprintuloadu	randrangeureverseuextendulenuAssertionError(unufnufpuresultumsguiutemp((uru2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu
randfloatss<
	


+



u
randfloatscCstjj�dS(N(usysustdoutuflush(((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyuflush8suflushcCsEtj�}|j�tj�}td||dd�t�dS(Nu%6.2fuendu (utimeuperf_counterusortuprintuflush(uLut0ut1((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyudoit;s

udoitc
Csctdd�dD��}ddt|�}t|d|�x|D]}d|>}t|�}td	||fd
d�t�t|�|j�t|�t|�xOtd�D]A}tj	|�}tj	|�}||||||<||<q�Wt|�|d
kr9dd�td
�D�|dd�<nt|�x1t|d�D]}tj�|tj	|�<qTWt|�|dkr�|dd�=||d}t
tdd�|��}nt|�~t
ttdg|��}t|�~|d}	t
t|	ddd��}|j
t|	��t
tt|��}t|�t�qFWdS(u: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

    cSsg|]}|d�qS(usort((u.0uch((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp>Us	utabulate.<locals>.<listcomp>u	*\/3+%~=!u%2s %7su %6suiu2**iiu%2d %7duendu ii
cSsg|]}tj��qS((urandom(u.0udummy((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp>ks	NidicSs|S(N((ux((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu<lambda>ysutabulate.<locals>.<lambda>g�?i(uiu2**ii����g�i����i����(utupleulenuprintu
randfloatsuflushudoitureverseurangeurandomu	randrangeulistumapuabsuextendufloat(
urucasesufmtuiunuLudummyui1ui2uhalf((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyutabulateBsL





!
&






utabulatecCs�d}d}tjdd�r�ttjd�}}tjdd�r�ttjd�}tjdd�r�d}x/tjdd�D]}d|t|�}q�Wtj|�q�q�nt||d�}t|�dS(u�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.

    iiiNiii�
(usysuargvuintuhashurandomuseedurangeutabulate(uk1uk2uxuaur((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyumain�s	umainu__main__(u__doc__usysutimeurandomumarshalutempfileuosu
gettempdirutdu
randfloatsuflushudoitutabulateumainu__name__(((u2/opt/alt/python33/lib64/python3.3/test/sortperf.pyu<module>s'L