ó
§«Õ\c           @  s!  d  Z  d d l m Z d d l Z e j d  d k rd d l Z d d l Z d d l Z d d l m	 Z	 d „  Z
 d „  Z e j d	 d
 ƒ e
 ƒ Z e j d	 d
 ƒ e
 ƒ Z e j d	 d
 d e ƒ e ƒ Z e j d	 d
 d e ƒ e ƒ Z d d
 d d „ Z d „  Z d e d „ Z d „  Z n  d S(   s¶    Benchmark against functools.lru_cache.

    Benchmark script from http://bugs.python.org/file28400/lru_cache_bench.py
    with a few modifications.

    Not available for Py < 3.3.
iÿÿÿÿ(   t   print_functionNi   i   (   t   countc          O  s   d  S(   N(    (   t   argst   kwargs(    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   _untyped   s    c          O  s   d  S(   N(    (   R   R   (    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   _typed   s    t   maxsizeid   t   typedi   c         c  so   xh t  |  | ƒ D]W } xN t  | ƒ D]@ } x7 t t  | ƒ t | d ƒ ƒ D] \ } } | | f VqH Wq# Wq Wd  S(   Niÿÿÿÿ(   t   ranget   zipR   (   t   mint   maxt   repeatt   it   rt   jt   k(    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   _arg_gen   s    +c           sY   t  d ƒ t  d j d d d d ƒ ƒ ‡  f d †  } | d d d	 ƒ | d
 d d ƒ d  S(   Nt    s   {:9s} {:>6s} {:>6s} {:>6s}R
   t   meanR   c           sŠ   g  t  ˆ  | d  d … ˆ  | d  d … ƒ D] \ } } | d | d ^ q* } t d j |  t | ƒ t | ƒ t | ƒ t | ƒ ƒ ƒ d  S(   Ni   i    s   {:9s} {:6.3f} {:6.3f} {:6.3f}(   R	   t   printt   formatR
   t   sumt   lenR   (   t   namet   off0t   off1t   pyt   ct   arr(   t   results(    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   print_stats(   s    8	t   untypedi    i   R   i   i   (   R   R   (   R   R   (    (   R   s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   _print_speedup%   s
    
c         C  s§   | r t  d j d d ƒ ƒ n„ t  d j |  d d j d ƒ d |  d d |  d d ƒ d	 d
 ƒt  d j |  d d j d ƒ d |  d d |  d d ƒ ƒ d  S(   Ns   {:29s} {:>8s}s   function calls   speed ups   {:32s} {:5.2f}i    i   t   _iÿÿÿÿt   ends   , i   i   (   R   R   t   split(   t   rest   init(    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   _print_single_speedup2   s    !$!c          C  s¿  t  d d d ƒt  d ƒ t  d ƒ t  d d d ƒt d t ƒ g  }  d d	 d
 d d d g } x | D]ˆ } xq d d d d g D]] } d | | f } t t j d j | ƒ d d | d d d d ƒƒ } |  j | | g ƒ q Wt |  d ƒ qf Wt |  ƒ t  d d d ƒt  d ƒ t  d d d ƒd d } g  }  xk d d d d g D]W } d  | } t t j d! | d | j | ƒ d d" d d# ƒƒ } |  j | | g ƒ qIWt d t ƒ t |  ƒ d  S($   Ns   Test Suite 1 : R#   s   

s>   Primarily tests cost of function call, hashing and cache hits.s   Benchmark script based ons7       http://bugs.python.org/file28400/lru_cache_bench.pyR&   R   s	   "spam", is   "spam", "spam", is   a=is   a="spam", b=is   a="spam", b="spam", c=it   _py_untypedt
   _c_untypedt	   _py_typedt   _c_typeds   %s(%s)sM   
                for i in range(100):
                    {}
                t   setups"   from fastcache.benchmark import %sR   i
   t   numberiè  iüÿÿÿs   

Test Suite 2 :s9   Tests millions of misses and millions of hits to quantifys"   cache behavior when cache is full.s#   from fastcache.benchmark import {}
s(   from fastcache.benchmark import _arg_gens   %s(i, j, a="spammy")sD   
            for i, j in _arg_gen():
                %s
            i   id   (	   R   R'   t   TrueR
   t   timeitR   R   t   appendR!   (   R   R   t   at   ft   st   tR,   (    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   run:   sB    

			



	(   i   i   (   t   __doc__t
   __future__R    t   syst   version_infot	   functoolst	   fastcacheR/   t	   itertoolsR   R   R   t	   lru_cacheR(   t
   clru_cacheR)   R.   R*   R+   R   R!   t   Nonet   FalseR'   R5   (    (    (    s2   lib/python2.7/site-packages/fastcache/benchmark.pyt   <module>   s"   			