Your IP : 216.73.216.213
�
��f� c @ s� 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 d � Z d d � Z
d d � Z d d
� Z d d � Z
e d
k r� e
� n d S( u_ Sort performance test.
See main() for command line syntax.
See tabulate() for output format.
i Nc s� t j j t d | � } y t | d � } Wn� t k
rt j � � f d d � t | � D� } ym z3 t | d � } t j | | � | j
� d } Wd | r� y t j | � Wq� t j
k
r� Yq� Xn XWn8 t k
r} z t d | d | � WYd d } ~ Xn XYnw Xt j | � } | j
� xZ t d � D]L } t j | � } | d | � } | d | � =| j � | j | � ~ q7W| S(
u+ Return a list of n random floats in [0, 1).u rr%06du rbc s g | ] } � � � q S( ( ( u .0u i( u r( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp> s u randfloats.<locals>.<listcomp>u wbNu can't writeu :i
( u osu pathu joinu tdu openu IOErroru randomu rangeu marshalu dumpu closeu Noneu unlinku erroru printu loadu randrangeu reverseu extend( u nu fnu fpu resultu msgu iu temp( ( u ru2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu
randfloats s:
+
u
randfloatsc C s t j j � d S( N( u sysu stdoutu flush( ( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu flush8 s u flushc C sE t j � } | j � t j � } t d | | d d �t � d S( Nu %6.2fu endu ( u timeu perf_counteru sortu printu flush( u Lu t0u t1( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu doit; s
u doitc
C sc t d d � d D� � } d d t | � } t | d | � x| D]} d | >} t | � } t d | | f d
d �t � t | � | j � t | � t | � xO t d � D]A } t j | � } t j | � } | | | | | | <| | <q� Wt | � | d
k r9d d � t d
� D� | d d � <n t | � x1 t | d � D] } t j � | t j | � <qTWt | � | d k r�| d d � =| | d } t
t d d � | � � } n t | � ~ t
t t d g | � � } t | � ~ | d } t
t | d d d � � } | j
t | � � t
t t | � � } t | � t � qF Wd S( 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
c S s g | ] } | d � q S( u sort( ( u .0u ch( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp>U s u tabulate.<locals>.<listcomp>u *\/3+%~=!u %2s %7su %6su iu 2**ii u %2d %7du endu i i
c S s g | ] } t j � � q S( ( u random( u .0u dummy( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu
<listcomp>k s Nid i c S s | S( N( ( u x( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu <lambda>y s u tabulate.<locals>.<lambda>g �?i ( u iu 2**ii����g �i����i����( u tupleu lenu printu
randfloatsu flushu doitu reverseu rangeu randomu randrangeu listu mapu absu extendu float(
u ru casesu fmtu iu nu Lu dummyu i1u i2u half( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu tabulateB sL
!
&
u tabulatec C s� d } d } t j d d � r� t t j d � } } t j d d � r� t t j d � } t j d d � r� d } x/ t j d d � D] } d | t | � } q� Wt j | � q� q� n t | | d � } t | � d S( 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.
i i i Ni i i�
( u sysu argvu intu hashu randomu seedu rangeu tabulate( u k1u k2u xu au r( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu main� s u mainu __main__( u __doc__u sysu timeu randomu marshalu tempfileu osu
gettempdiru tdu
randfloatsu flushu doitu tabulateu mainu __name__( ( ( u2 /opt/alt/python33/lib64/python3.3/test/sortperf.pyu <module> s 'L