3
d                 @   s  d Z ddl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	 qRW e Zx eeD ]Zed
jed	 qzW dZx4ee
D ](Zx"eeD ]Zeejeed qW qW e ZdZx8ee
D ],Zx&eeeD ]Zeejeed qW qW 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	 qfW e! Zx"eeD ]Zedjed	 qW dZ"x8ee
D ],Zx$eeD ]Zee"jeed qW qW e ZdZ#x<ee
D ]0Z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$ qbW 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 ;^).

    N)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 iterationz$
class FooABC{i}(abc.ABC):
    pass
zclass Foo{i}(object): passzFooABC{i}.register(Foo{i})z!
class ABC{i}(abc.ABC):
    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__abc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   C/tmp/pip-build-7vycvbft/traits/traits/adaptation/tests/benchmark.py<module>   sh   


