
    v5`m                         d dl Z d dlmZmZ d dlmZ d dlmZ ddlmZmZ  ej	                    Z edg d          Z
d	Zd
ZdZdZ G d d          Zedk    re                                 dS dS )    N)defaultdict
namedtuple)timeit)tabulate   )LIBRARIES_FILE	prototypeLib	algorithmlibraryfunctiontimepresetszc
from {library} import {function} as func
presets = {presets}
if presets:
    func = func(presets)
z?
from textdistance import {} as cls
func = cls(external=False)
zD
func('text', 'test')
func('qwer', 'asdf')
func('a' * 15, 'b' * 15)
i  c                       e Zd Zed             Zed             Zed             Zed             Zed             Zed             Z	e
d             ZdS )		Benchmarkc            
   #   
  K   t                                           D ]f} t                               |           D ]I}|                                st	          | |j        |j        t          d          |j                  V  Jgd S )NInfr   )		librariesget_algorithmsget_libsget_functionr
   module_name	func_namefloatr   )alglibs     6lib/python3.11/site-packages/textdistance/benchmark.pyget_installedzBenchmark.get_installed*   s      ++-- 	 	C ))#..  '')) !O ]uK      	 	    c              #      K   | D ]U}|                     t          t          t          j        di |                                t                              V  Vd S )Nstmtsetupnumber)r    )_replacer   STMTEXTERNAL_SETUPformat_asdictRUNS)	installedr   s     r   get_external_benchmarkz Benchmark.get_external_benchmark:   sy       	 	C,,F$+<<ckkmm<<% % %,      	 	r    c               #      K   t                                           D ]J} t          | d| t          t          t
                              |           t                    d           V  Kd S )Nz**textdistance**r"   r   )r   r   r
   r   r(   INTERNAL_SETUPr*   r,   )r   s    r   get_internal_benchmarkz Benchmark.get_internal_benchmarkC   s      ++-- 	 	C*(//44  
 
 
 
 
 
 
 
	 	r    c                 B    d |D             t          fd|           S )Nc                 (    i | ]}|j         |j        S r&   r   r   .0is     r   
<dictcomp>z.Benchmark.filter_benchmark.<locals>.<dictcomp>T   s    888!!+qv888r    c                 0    | j         | j                 k     S N)r   r   )xlimitss    r   <lambda>z,Benchmark.filter_benchmark.<locals>.<lambda>U   s    )< < r    )filter)externalinternalr<   s     @r   filter_benchmarkzBenchmark.filter_benchmarkR   s0    88x888<<<<hGGGr    c                     t          d | D             g dd          }|d                    t          |                     z  }|S )Nc                 <    g | ]}t          |d d                   S )N)tupler5   s     r   
<listcomp>z'Benchmark.get_table.<locals>.<listcomp>Z   s&    )))qU1SbS6]])))r    )r   r   r   r   orgtbl)headerstablefmtz
Total: {} libs.

)r   r*   len)datatables     r   	get_tablezBenchmark.get_tableW   sY    ))D)))@@@
 
 

 	(//D		:::r    c                    t          t                    }| D ].}||j                                     |j        |j        g           /t          t          d          5 }t          j	        ||dd           d d d            d S # 1 swxY w Y   d S )Nw   T)objfpindent	sort_keys)
r   listr   appendr   r   openr   jsondump)libsrK   r   fs       r   savezBenchmark.savea   s    4   	D 	DC&&S\'BCCCC.#&& 	@!I$1Q$????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   BBBc                    t          d           t          |                                           }|                                 t          |                     |                     t          d           t          |                     |                    }t          |                                           }||z  }|                    d            t          |                     |                     t          d           t          |                     ||                    }t          |                     |                     |                     |           d S )Nz# Installed libraries:
z"# Benchmarks (with textdistance):
c                     | j         | j        fS r:   r4   )r;   s    r   r=   zBenchmark.run.<locals>.<lambda>t   s    ak16%: r    )keyz# Faster than textdistance:
)	printrU   r   sortrM   r.   r1   rA   r\   )clsr-   	benchmarkbenchmark_internals       r   runzBenchmark.runi   s4   ()))**,,--	cmmI&&'''344433I>>??	!#"<"<">">??''	::;;;cmmI&&'''-...--i9KLLMM	cmmI&&'''r    N)__name__
__module____qualname__staticmethodr   r.   r1   rA   rM   r\   classmethodre   r&   r    r   r   r   )   s          \   \   \ H H \H   \ @ @ \@   [  r    r   __main__)rX   collectionsr   r   r   r   r   r   r	   cloner
   r)   r0   r(   r,   r   rf   re   r&   r    r   <module>rn      s    / / / / / / / /             1 0 0 0 0 0 0 0 IO	jOOOPP
 R R R R R R R Rj zMMOOOOO r    