ó
wŰjc           @   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   Z	 d   Z
 d   Z d   Z d   Z e d k r e   n  d S(	   s_   Sort performance test.

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

i˙˙˙˙Nc         C   sl  t  j j t d |   } y t | d  } WnĎ t k
 rý t j } g  t |   D] } |   ^ qR } yl z3 t | d  } t j	 | |  | j
   d } Wd | rŃ y t  j |  WqŃ t  j k
 rÍ qŃ Xn  XWqht k
 rů } d G| Gd G| GHqhXnk Xt j |  } | j
   xN t d  D]@ } t j |   } | |  } | | 4| j   | j |  ~ q$W| S(   s+   Return a list of n random floats in [0, 1).s   rr%06dt   rbt   wbNs   can't writet   :i
   (   t   ost   patht   joint   tdt   opent   IOErrort   randomt   xranget   marshalt   dumpt   closet   Nonet   unlinkt   errort   loadt   ranget	   randranget   reverset   extend(   t   nt   fnt   fpt   rt   it   resultt   msgt   temp(    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt
   randfloats   s:    	"




c           C   s   t  j j   d  S(   N(   t   syst   stdoutt   flush(    (    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyR!   8   s    c         C   s9   t  j   } |  j   t  j   } d | | Gt   d  S(   Ns   %6.2f(   t   timet   clockt   sortR!   (   t   Lt   t0t   t1(    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt   doit;   s
    
c         C   s;  t  g  d D] } | d ^ q
  } d d t |  } | d | GHxđ|  D]č} d | >} t |  } d | | f Gt   t |  | j   t |  t |  xO t d	  D]A } t j |  } t j |  }	 | |	 | | | | <| |	 <qą Wt |  | d
 k r8g  t d
  D] } t j   ^ q| d )n  t |  x1 t	 | d  D] } t j   | t j |  <qSWt |  | d k rś| d 3| | d } t
 d   |  } n  t |  ~ t
 t d g |  } t |  ~ | d }
 t |
 d d d  } | j t |
   t
 t |  } t |  HqK Wd S(   s:  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

    s	   *\/3+%~=!R$   s   %2s %7ss    %6sR   s   2**ii   s   %2d %7di   i
   iö˙˙˙id   i   c         S   s   |  S(   N(    (   t   x(    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt   <lambda>y   t    g      ŕżi   i˙˙˙˙N(   R   s   2**i(   t   tuplet   lenR   R!   R(   R   R   R	   R   R
   t   mapt   absR   t   float(   R   t   cht   casest   fmtR   R   R%   t   dummyt   i1t   i2t   half(    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt   tabulateB   sL    #




!
,





c          C   sĆ   d }  d } t  j d rĽ t t  j d  }  } t  j d rĽ t t  j d  } t  j d r˘ d } x) t  j d D] } d | t |  } qq Wt j |  q˘ qĽ n  t |  | d  } t |  d S(   sÂ   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   i   i   iÍ N(   R   t   argvt   intt   hashR	   t   seedR   R8   (   t   k1t   k2R)   t   aR   (    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt   main   s    	t   __main__(   t   __doc__R   R"   R	   R   t   tempfileR   t
   gettempdirR   R   R!   R(   R8   R@   t   __name__(    (    (    s   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/sortperf.pyt   <module>   s   	'			L	