3
8ßL]f  ã               @   sº  d Z ddlmZ ddlZddlmZ ddlZddlmZ ddlm	Z	m
Z
mZmZ dZdZd	Zd
Zx eeƒD ]Zeejed�ƒ qjW eƒ Zx eeƒD ]Zedjed�ƒ q’W dZx4eeƒD ](Zx"eeƒD ]Zeejeed�ƒ qÆW q¸W eƒ ZdZx:eeƒD ].Zx(eeeƒƒD ]Zeejeed�ƒ �q
W qøW ejƒ ZxeeƒD ]Zejee ƒ �q<W ejƒ e e!eƒ d Z"e#de" ƒ xBeeƒD ]6Zedjed�ƒ edjed�ƒ edjed�ƒ �q€W e$ƒ Zx"eeƒD ]Zedjed�ƒ �qÊW dZ%x8eeƒD ],Zx$eeƒD ]Zee%jeed�ƒ �q W �qòW eƒ ZdZ&x<eeƒD ]0Zx(eeeƒƒD ]Zee&jeed�ƒ �qHW �q6W ejƒ ZxeeƒD ]Zejee'ƒ �q|W ejƒ e e!eƒ d Z"e#de" ƒ dS )z¿ Simple benchmarking of the adaptation manager.

This is not 'enforced' by any tests (i.e. we currently aren't bound to satisfy
any performance criteria - but in the future we might be ;^).

é    )Úprint_functionN)Úpprint)ÚAdaptationManager)ÚAdapterÚ	HasTraitsÚ	InterfaceÚprovidesé   éd   é2   zZ
class IFoo{i}(Interface):
    pass

@provides(IFoo{i})
class Foo{i}(HasTraits):
    pass
)Úizclass I{i}(Interface): passzG
@provides(I{target})
class IFoo{source}ToI{target}(Adapter):
    pass
)ÚsourceÚtargetz—

adaptation_manager.register_factory(
    factory       = IFoo{source}ToI{target},
    from_protocol = IFoo{source},
    to_protocol   = I{target}
)

g     @�@z2apptools using Interfaces: %.3f msec per iterationzC
@six.add_metaclass(abc.ABCMeta)
class FooABC{i}(object):
    pass
zclass Foo{i}(object): passzFooABC{i}.register(Foo{i})z@
@six.add_metaclass(abc.ABCMeta)
class ABC{i}(object):
    pass
z�
class FooABC{source}ToABC{target}(object):
    def __init__(self, adaptee):
        pass

ABC{target}.register(FooABC{source}ToABC{target})
z�
adaptation_manager.register_factory(
    factory       = FooABC{source}ToABC{target},
    from_protocol = FooABC{source},
    to_protocol   = ABC{target}
)
z,apptools using ABCs: %.3f msec per iteration)(Ú__doc__Ú
__future__r   Úabcr   ÚtimeZ$traits.adaptation.adaptation_managerr   Z
traits.apir   r   r   r   Z	N_SOURCESZN_ITERATIONSZN_PROTOCOLSZcreate_classes_to_adaptÚranger   ÚexecÚformatZFoo1ZfooZcreate_traits_adapter_classr   r   Zadaptation_managerZregister_ifoox_to_ixÚreversedÚ
start_timeÚ_ZadaptZI0ÚfloatZtime_per_iterÚprintZFoo0Zcreate_abc_adapter_classZregister_fooxabc_to_abcxZABC0© r   r   úE/tmp/pip-install-5sebvq2j/traits/traits/adaptation/tests/benchmark.pyÚ<module>   sl   


