ó {G_Tc@sĄdZddlZddlZddlZddlZddlZddlZejƒZd„Z d„Z d„Z d„Z d„Z edkre ƒndS( s_Sort performance test. See main() for command line syntax. See tabulate() for output format. i˙˙˙˙NcCsltjjtd|ƒ}yt|dƒ}WnĎtk rýtj}gt|ƒD]}|ƒ^qR}ylz3t|dƒ}tj ||ƒ|j ƒd}Wd|rŃytj |ƒWqŃtj k rÍqŃXnXWqhtk rů}dG|GdG|GHqhXnkXtj|ƒ}|j ƒxNtdƒD]@}tj|ƒ}|| }||4|jƒ|j|ƒ~q$W|S(s+Return a list of n random floats in [0, 1).srr%06dtrbtwbNs can't writet:i (tostpathtjointtdtopentIOErrortrandomtxrangetmarshaltdumptclosetNonetunlinkterrortloadtranget randrangetreversetextend(tntfntfptrtitresulttmsgttemp((s)/usr/local/lib/python2.7/test/sortperf.pyt randfloatss:  "       cCstjjƒdS(N(tsyststdouttflush(((s)/usr/local/lib/python2.7/test/sortperf.pyR!8scCs9tjƒ}|jƒtjƒ}d||GtƒdS(Ns%6.2f(ttimetclocktsortR!(tLtt0tt1((s)/usr/local/lib/python2.7/test/sortperf.pytdoit;s     c Cs;tgdD]}|d^q ƒ}ddt|ƒ}|d|GHxđ|D]č}d|>}t|ƒ}d||fGtƒt|ƒ|jƒt|ƒt|ƒxOtd ƒD]A}tj|ƒ}tj|ƒ} || ||||<|| ysgŕżii˙˙˙˙N(Rs2**i(ttupletlenRR!R(RRR RR tmaptabsRtfloat( RtchtcasestfmtRRR%tdummyti1ti2thalf((s)/usr/local/lib/python2.7/test/sortperf.pyttabulateBsL#        !  ,       cCsĆd}d}tjdrĽttjdƒ}}tjdrĽttjdƒ}tjdr˘d}x)tjdD]}d|t|ƒ}qqWtj|ƒq˘qĽnt||dƒ}t|ƒdS(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. iiiiiiÍ N(RtargvtintthashR tseedRR7(tk1tk2R)taR((s)/usr/local/lib/python2.7/test/sortperf.pytmainŽs    t__main__(t__doc__RR"R R ttempfileRt gettempdirRRR!R(R7R?t__name__(((s)/usr/local/lib/python2.7/test/sortperf.pyts        '   L