relateby-pattern 0.3.1

Core pattern data structures
Documentation
�

tzi�5���dZddlZddlmcmZddlZddlZddl	m
Z
mZmZGd�d��Z
Gd�d��ZGd�d	��ZGd
�d��ZGd�d
��ZGd�d��Zedkrejeddg��dSdS)a)Performance tests for Python pattern-core bindings.

Tests that Python bindings maintain performance within 2x of native Rust operations.

Note: These are basic performance tests to verify the bindings don't introduce
catastrophic overhead. Detailed benchmarks should be run with dedicated tools.
�N)�Pattern�PatternSubject�Subjectc�$�eZdZdZd�Zd�Zd�ZdS)�TestConstructionPerformancez&Test pattern construction performance.c	�.�d}tj��}t|��D]}tj|��}�tj��|z
}d}||k}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}dd|iz}	tt	j|	�����d	x}}td
|�d|d�d
||zd�d���d	S)z8Creating many atomic patterns should be reasonably fast.����?��<�z%(py0)s < %(py3)s�elapsed��py0�py3�assert %(py5)s�py5Nz
Point creation: �
 patterns in �.4f�s (�.1f�	 ops/sec))
�time�ranger�point�
@pytest_ar�_call_reprcompare�@py_builtins�locals�_should_repr_global_name�	_saferepr�AssertionError�_format_explanation�print�
�self�
iterations�start�i�_r�@py_assert2�@py_assert1�@py_format4�@py_format6s
          �b/Users/akollegger/Developer/gram-data/gram-rs/crates/pattern-core/tests/python/test_performance.py�test_point_creation_performancez;TestConstructionPerformance.test_point_creation_performancesI���
��	�����z�"�"�	!�	!�A��
�a� � �A�A��)�+�+��%����w��}����������w��������������w������w���������������������������������
�m�:�m�m�G�m�m�m�J�W^�L^�m�m�m�m�n�n�n�n�n�c	�~�d}tj��}t|��D]>}tj|��}td��D]}tj||g��}��?tj��|z
}d}||k}|s�tjd|fd||f��dtj��vstj	|��rtj
|��ndtj
|��d�z}	dd	|	iz}
ttj|
�����d
x}}td|�d|d
�d||zd�d���d
S)z3Creating nested patterns should be reasonably fast.�d�
�@rr
rrrrNz
Nested pattern creation: rrrrr)rrrr�patternrrrrr r!r"r#r$)r&r'r(r)�node�jrr+r,r-r.s           r/�(test_nested_pattern_creation_performancezDTestConstructionPerformance.test_nested_pattern_creation_performancesw���
��	�����z�"�"�	2�	2�A��=��#�#�D��2�Y�Y�
2�
2����q�4�&�1�1���
2��)�+�+��%����w��}����������w��������������w������w���������������������������������
�v�J�v�v�W�v�v�v�U_�`g�Ug�v�v�v�v�w�w�w�w�wr1c	��d}d}tj��}t|��D]E}tt|����}tjdtj|����}�Ftj��|z
}d}||k}	|	s�t
jd|	fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��d�z}
dd	|
iz}tt
j
|�����d
x}	}||z}td|�d|�d
|d�d���d
S)z7Creating patterns from lists should be reasonably fast.r3�rootr5rr
rrrrNz
List pattern creation: z patterns (z elements) in r�s)rr�listrr6�from_valuesrrrrr r!r"r#r$)
r&r'�	list_sizer(r)�datar*rr+r,r-r.�total_elementss
             r/�&test_list_pattern_creation_performancezBTestConstructionPerformance.test_list_pattern_creation_performance-st���
��	��	�����z�"�"�	C�	C�A���i�(�(�)�)�D�����(;�D�(A�(A�B�B�A�A��)�+�+��%����w��}����������w��������������w������w���������������������������������#�i�/��
�m�*�m�m��m�m�_f�m�m�m�m�n�n�n�n�nr1N)�__name__�
__module__�__qualname__�__doc__r0r9rB�r1r/rrsR������0�0�o�o�o�
x�
x�
x�o�o�o�o�or1rc�*�eZdZdZd�Zd�Zd�Zd�ZdS)�TestOperationPerformancez#Test pattern operation performance.c
��d}tjdtjtt	|��������}tj��}|�d���}tj��|z
}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}d	d
|iz}	ttj|	�����dx}}td|�d
|dzd�d||zd�d���dS)z(Map operation should be reasonably fast.r	r;c��|dzS�N�rG��xs r/�<lambda>z?TestOperationPerformance.test_map_performance.<locals>.<lambda>Gs
��A��E�r1皙�����?rr
rrrrNz

Map over � elements: �.2f�ms (rr)rr6r>r=rr�maprrrrr r!r"r#r$�
r&�size�pr(r*rr+r,r-r.s
          r/�test_map_performancez-TestOperationPerformance.test_map_performanceAs`�����O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	����
�E�E�/�/�"�"���)�+�+��%����w��}����������w��������������w������w���������������������������������
�^�D�^�^�W�T�\�^�^�^�4��<�^�^�^�^�_�_�_�_�_r1c
��d}tjdtjtt	|��������}tj��}|�d���}tj��|z
}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}d	d
|iz}	ttj|	�����dx}}td|�d
|dzd�d||zd�d���dS)z+Filter operation should be reasonably fast.r	r;c��|dzdkS)NrMrrGrNs r/rPzBTestOperationPerformance.test_filter_performance.<locals>.<lambda>Ts��q�1�u��z�r1皙�����?rr
rrrrNz
Filter over rRrSrTrr)rr6r>r=rr�filterrrrrr r!r"r#r$rVs
          r/�test_filter_performancez0TestOperationPerformance.test_filter_performanceNsb�����O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	����
�H�H�)�)�*�*���)�+�+��%����w��}����������w��������������w������w���������������������������������
�a�t�a�a����a�a�a�d�7�l�a�a�a�a�b�b�b�b�br1c
��d}tjdtjtt	|��������}tj��}|�dd���}tj��|z
}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d	�z}d
d|iz}	ttj|	�����dx}}d
}
||
z}t|k}|s�tjd|fdt|f��dtj
��vstjt��rtjt��nddtj
��vstj|��rtj|��ndtj|
��d�z}	dd|	iz}ttj|�����dx}x}
}t!d|�d|dzd�d||zd�d���dS)z)Fold operation should be reasonably fast.r	r;rc��|dzS�N�rG��accrOs  r/rPz@TestOperationPerformance.test_fold_performance.<locals>.<lambda>as
��S�1�W�r1rQrr
rrrrNrb��==�z%(py0)s == (%(py2)s + %(py4)s)�resultrW�r�py2�py4�assert %(py7)s�py7z
Fold over rRrSrTrr)rr6r>r=rr�foldrrrrr r!r"r#rhr$)
r&rWrXr(r*rr+r,r-r.�@py_assert3�@py_assert5�@py_format8s
             r/�test_fold_performancez.TestOperationPerformance.test_fold_performance[so�����O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	����
�F�F�1�,�,�-�-���)�+�+��%����w��}����������w��������������w������w��������������������������������� !�!����!�v��!�!�!�!�!�!�!�!�!�!�v��!�!�!�!�!�!�!�!�!�!�!�!�v�!�!�!�!�!�v�!�!�!�!�!�!�!�!�!�!�!�!�!��!�!�!�!�!��!�!�!�!�!�!��!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�
�_�T�_�_�g�d�l�_�_�_�D��L�_�_�_�_�`�`�`�`�`r1c
�z�d}tjdtjtt	|��������}tj��}d}|���D]}|dz
}�tj��|z
}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d	�z}	d
d|	iz}
ttj|
�����dx}}d}||z}||k}|s�tjd
|fd||f��dtj
��vstj|��rtj|��nddtj
��vstj|��rtj|��ndtj|��d�z}
dd|
iz}
ttj|
�����dx}x}}td|�d|dzd�d||zd�d���dS)z0Iterating over values should be reasonably fast.r	r;rrbrQrr
rrrrNrerg�countrWrirlrmz
Values iteration over rRrSrTrr)rr6r>r=rr�valuesrrrrr r!r"r#r$)r&rWrXr(rtr*rr+r,r-r.rorprqs              r/�!test_values_iteration_performancez:TestOperationPerformance.test_values_iteration_performanceis������O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	�����������	�	�A��Q�J�E�E��)�+�+��%����w��}����������w��������������w������w��������������������������������� � ��q�� �u�� � � � � � � � � � �u�� � � � � � � � � � � � �u� � � � � �u� � � � � � � � � � � � � �� � � � � �� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � �
�k��k�k�'�$�,�k�k�k�PT�U\�P\�k�k�k�k�l�l�l�l�lr1N)rCrDrErFrYr^rrrvrGr1r/rIrI>sd������-�-�`�`�`�c�c�c�a�a�a�m�m�m�m�mr1rIc�$�eZdZdZd�Zd�Zd�ZdS)�TestSubjectPerformancez#Test Subject operation performance.c	�*�d}tj��}t|��D]}td|����}�tj��|z
}d}||k}|s�tjd|fd||f��dtj��vstj|��rtj|��ndtj|��d�z}dd	|iz}	ttj
|	�����d
x}}td|�d|d
�d||zd�d���d
S)z1Creating many subjects should be reasonably fast.r	�subj-r
rr
rrrrNz
Subject creation: z
 subjects in rrrr)rrrrrrrr r!r"r#r$r%s
          r/�!test_subject_creation_performancez8TestSubjectPerformance.test_subject_creation_performance}sM���
��	�����z�"�"�	%�	%�A������$�$�A�A��)�+�+��%����w��}����������w��������������w������w���������������������������������
�o�Z�o�o�g�o�o�o�j�Y`�N`�o�o�o�o�p�p�p�p�pr1c	��d}d}tj��}t|��D]>}td|����}t|��D]}|�d|������?tj��|z
}d}||k}	|	s�t	jd|	fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d	�z}
d
d|
iz}tt	j|�����dx}	}||z}td
|�d|d�d||zd�d���dS)z+Label operations should be reasonably fast.r3r4rz�Labelr
rr
rrrrNz
Subject label operations: � operations in rrrr)
rrr�	add_labelrrrrr r!r"r#r$)
r&r'�labels_per_subjectr(r)r<r8rr+r,r-r.�	total_opss
             r/�)test_subject_label_operations_performancez@TestSubjectPerformance.test_subject_label_operations_performance�s����
����	�����z�"�"�	)�	)�A������$�$�A��-�.�.�
)�
)�����K�A�K�K�(�(�(�(�
)��)�+�+��%����w��}����������w��������������w������w����������������������������������!3�3�	�
�w�Y�w�w�w�w�w�w�W`�ah�Wh�w�w�w�w�x�x�x�x�xr1c	��d}d}tj��}t|��D]?}td|����}t|��D]}|�d|��|����@tj��|z
}d}||k}	|	s�t	jd|	fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d	�z}
d
d|
iz}tt	j|�����dx}	}||z}td
|�d|d�d||zd�d���dS)z.Property operations should be reasonably fast.r3r4rz�propr
rr
rrrrNz
Subject property operations: r~rrrr)
rrr�set_propertyrrrrr r!r"r#r$)
r&r'�props_per_subjectr(r)r<r8rr+r,r-r.r�s
             r/�,test_subject_property_operations_performancezCTestSubjectPerformance.test_subject_property_operations_performance�s����
����	�����z�"�"�	.�	.�A������$�$�A��,�-�-�
.�
.�����z�a�z�z�1�-�-�-�-�
.��)�+�+��%����w��}����������w��������������w������w����������������������������������!2�2�	�
�z�	�z�z�'�z�z�z�Zc�dk�Zk�z�z�z�z�{�{�{�{�{r1N)rCrDrErFr{r�r�rGr1r/rxrxzsR������-�-�q�q�q�y�y�y�"|�|�|�|�|r1rxc�$�eZdZdZd�Zd�Zd�ZdS)�TestLargeStructurePerformancez:Test performance with large structures (up to 1000 nodes).c
�d�d}tjdtjtt	|��������}tj��}|���}tj��|z
}|j}|��}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��tj|��dtj
��vstj|��rtj|��ndd�z}	dd	|	iz}
ttj|
�����d
x}x}}tj��}|���}tj��|z
}|j}|��}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��tj|��dtj
��vstj|��rtj|��ndd�z}	dd	|	iz}
ttj|
�����d
x}x}}tj��}|���}tj��|z
}|j}|��}d
}
||
k}|s�tjd|fd||
f��dtj
��vstj|��rtj|��ndtj|��tj|��tj|
��d�z}dd|iz}ttj|�����d
x}x}x}}
d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj|�����d
x}}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj|�����d
x}}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj|�����d
x}}t#d|�d���t#d|dzd�d���t#d |dzd�d���t#d!|dzd�d���d
S)"z/Operations on large flat patterns (1000 nodes).r	r;re�zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py6)srXrW�rrjrk�py6�assert %(py8)s�py8N)�>=)zC%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.size
}()
} >= %(py6)sr)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} >= %(py7)s)rrjrkrmzassert %(py9)s�py9�{�G�z�?rr
�elapsed_lengthrrr�elapsed_size�
elapsed_depthz
Large pattern (z nodes) inspection:z
  length: rS�msz  size: �	  depth: )rr6r>r=rr�lengthrrrrr r!r"r#rW�depthr$)r&rWrXr(r*r�r,rorp�@py_format7�@py_format9r�r��@py_assert6rq�@py_format10r+r-r.s                   r/�"test_large_flat_pattern_operationsz@TestLargeStructurePerformance.test_large_flat_pattern_operations�s������O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	����
�H�H�J�J������u�,���x�!�x�x�z�z�!�z�T�!�!�!�!�!�!�!�!�!�!�z�T�!�!�!�!�!�!�!�!�!�!�!�!�q�!�!�!�!�!�q�!�!�!�!�!�!�x�!�!�!�!�z�!�!�!�!�!�!�!�!�!�!�!�T�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��	����
�F�F�H�H���y�{�{�U�*���v��v�v�x�x��x�4�����������x�4�������������q������q�������v�����x������������4������4�������������������������������	����
�G�G�I�I���	���e�+�
��w��w�w�y�y��A��y�A�~����������y�A�������������q������q�������w�����y�����A������������������������������!%�$�~��$�$�$�$�$�$�$�$�$�$�~��$�$�$�$�$�$�$�$�$�$�$�$�~�$�$�$�$�$�~�$�$�$�$�$�$��$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�"�"�|�d�"�"�"�"�"�"�"�"�"�"�|�d�"�"�"�"�"�"�"�"�"�"�"�"�|�"�"�"�"�"�|�"�"�"�"�"�"�d�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�#�#�}�t�#�#�#�#�#�#�#�#�#�#�}�t�#�#�#�#�#�#�#�#�#�#�#�#�}�#�#�#�#�#�}�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�
�;�$�;�;�;�<�<�<�
�6�>�$�.�6�6�6�6�7�7�7�
�2��d�*�2�2�2�2�3�3�3�
�4�-��,�4�4�4�4�5�5�5�5�5r1c
��d}tjdtjtt	|��������}tj��}|�d���}tj��|z
}d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}d	d
|iz}	ttj|	�����dx}}|j}|��}
|
|k}|s�tjd|fd
|
|f��dtj
��vstj|��rtj|��ndtj|��tj|
��dtj
��vstj|��rtj|��ndd�z}dd|iz}
ttj|
�����dx}x}
}t!d|�d|dzd�d���dS)z?Transform large pattern (1000 nodes) within performance target.r	r;c��|dzSrLrGrNs r/rPzQTestLargeStructurePerformance.test_large_pattern_transformation.<locals>.<lambda>�s
��a�!�e�r1r\rr
rrrrNrer��transformedrWr�r�r�z
Large pattern transformation (z	 nodes): rSr�)rr6r>r=rrrUrrrrr r!r"r#r�r$)r&rWrXr(r�rr+r,r-r.rorpr�r�s              r/�!test_large_pattern_transformationz?TestLargeStructurePerformance.test_large_pattern_transformation�sy�����O�F�G�$7��U�4�[�[�8I�8I�$J�$J�K�K���	�����e�e�O�O�,�,���)�+�+��%����w��}����������w��������������w������w����������������������������������!�+�!�!�#�#�+�#�t�+�+�+�+�+�+�+�+�+�+�#�t�+�+�+�+�+�+�+�+�+�+�+�+�{�+�+�+�+�+�{�+�+�+�+�+�+�!�+�+�+�+�#�+�+�+�+�+�+�+�+�+�+�+�t�+�+�+�+�+�t�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�
�T��T�T����T�T�T�T�U�U�U�U�Ur1c�\�d}tjd��}tj��}t|��D]}tjd|��|g��}�tj��|z
}tj��}|���}tj��|z
}tj��}	|���}tj��|	z
}
d}||k}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��d�z}
d	d
|
iz}ttj|�����dx}}d}||k}|s�tjd|fd||f��d
tj
��vstj|��rtj|��nd
tj|��d�z}
d	d
|
iz}ttj|�����dx}}d}|
|k}|s�tjd|fd|
|f��dtj
��vstj|
��rtj|
��ndtj|��d�z}
d	d
|
iz}ttj|�����dx}}td|�d���td|dzd�d���td|dzd�d���td|
dzd�d���dS)z%Operations on deeply nested patterns.r3�*zlevel-rQrr
�
build_elapsedrrrNr��extract_elapsed�
depth_elapsedz
Deep pattern (z	 levels):�	  build: r	rSr�z  extract: r�)rrrrr6�extractr�rrrrr r!r"r#r$)r&r�rX�build_startr)r��
extract_startr*r��depth_startr�r+r,r-r.s               r/�test_deep_pattern_performancez;TestLargeStructurePerformance.test_deep_pattern_performance�s������M�"�����i�k�k���u���	3�	3�A�������q�c�2�2�A�A��	���k�1�
��	���
�
�I�I�K�K���)�+�+�
�5���i�k�k��
�G�G�I�I���	���k�1�
� #�"�}�s�"�"�"�"�"�"�"�"�"�"�}�s�"�"�"�"�"�"�"�"�"�"�"�"�}�"�"�"�"�"�}�"�"�"�"�"�"�s�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�!%�%���%�%�%�%�%�%�%�%�%�%���%�%�%�%�%�%�%�%�%�%�%�%��%�%�%�%�%��%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�#�#�}�t�#�#�#�#�#�#�#�#�#�#�}�t�#�#�#�#�#�#�#�#�#�#�#�#�}�#�#�#�#�#�}�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�
�1��1�1�1�2�2�2�
�4�-��,�4�4�4�4�5�5�5�
�8�O�D�0�8�8�8�8�9�9�9�
�4�-��,�4�4�4�4�5�5�5�5�5r1N)rCrDrErFr�r�r�rGr1r/r�r��sK������D�D�6�6�6�BV�V�V�"6�6�6�6�6r1r�c��eZdZdZd�Zd�ZdS)�TestComplexWorkflowPerformancez0Test performance of realistic complex workflows.c�d�d}tj��}g}t|��D]T}td|����}|�d��|�d|��|�|���Ud�|D��}t
jdt
j|����}tj��|z
}tj��}	|�	��}
|�
��}
|���}
tj��|	z
}tj��}|�d���}
tj��|z
}
d}||k}|s�tjd	|fd
||f��dtj��vstj|��rtj|��ndtj|��d�z}d
d|iz}t'tj|�����dx}}d}||k}|s�tjd	|fd
||f��dtj��vstj|��rtj|��ndtj|��d�z}d
d|iz}t'tj|�����dx}}d}|
|k}|s�tjd	|fd
|
|f��dtj��vstj|
��rtj|
��ndtj|��d�z}d
d|iz}t'tj|�����dx}}t+d|�d���t+d|dzd�d���t+d|dzd�d���t+d|
dzd�d���dS)z'Build and query a graph-like structure.r3znode-�Node�valuec�6�g|]}tj|����SrG)rr)�.0r<s  r/�
<listcomp>zTTestComplexWorkflowPerformance.test_graph_construction_and_query.<locals>.<listcomp>s#��>�>�>��N�(��+�+�>�>�>r1r;c��|S�NrGrNs r/rPzRTestComplexWorkflowPerformance.test_graph_construction_and_query.<locals>.<lambda>s���r1r
rr
r�rrrNrQ�
query_elapsedg�?�transform_elapsedz
Graph workflow (z nodes):r�r	rSr�z	  query: z
  transform: )rrrrr��appendrr6r>r�rWr�rUrrrrr r!r"r#r$)r&�	num_nodesr��subjectsr)r<�patterns�graphr��query_startr*r��transform_startr�r+r,r-r.s                  r/�!test_graph_construction_and_queryz@TestComplexWorkflowPerformance.test_graph_construction_and_querys���	��i�k�k�����y�!�!�	�	�A������$�$�A�
�K�K�����
�N�N�7�A�&�&�&��O�O�A�����>�>�X�>�>�>������(;�H�(E�(E�F�F���	���k�1�
��i�k�k���L�L�N�N���J�J�L�L���K�K�M�M���	���k�1�
��)�+�+���I�I�k�k�"�"�� �I�K�K�/�9�� #�"�}�s�"�"�"�"�"�"�"�"�"�"�}�s�"�"�"�"�"�"�"�"�"�"�"�"�}�"�"�"�"�"�}�"�"�"�"�"�"�s�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�}�s�"�"�"�"�"�"�"�"�"�"�}�s�"�"�"�"�"�"�"�"�"�"�"�"�}�"�"�"�"�"�}�"�"�"�"�"�"�s�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�#&�&� �3�&�&�&�&�&�&�&�&�&�&� �3�&�&�&�&�&�&�&�&�&�&�&�&� �&�&�&�&�&� �&�&�&�&�&�&�3�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�
�6�9�6�6�6�7�7�7�
�4�-��,�4�4�4�4�5�5�5�
�4�-��,�4�4�4�4�5�5�5�
�<�/��4�<�<�<�<�=�=�=�=�=r1c��d}tj��}d�t|��D��}tj��|z
}tj��}d�|D��}tjdtj|����}tj��|z
}tj��}	|�d���}
tj��|	z
}tj��}|
�dd���}
tj��|z
}||z|z|z}d}||k}|s�tjd	|fd
||f��dtj
��vstj|��rtj|��ndtj|��d�z}d
d|iz}ttj|�����dx}}d}||z}|
|k}|s�tjd|fd|
|f��dtj
��vstj|
��rtj|
��nddtj
��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj|�����dx}x}}td|�d���td|dzd�d���td|dzd�d���td|dzd�d���td |dzd�d���td!|dzd�d���dS)"z"Simulate data processing pipeline.i�c��g|]
}||dzd���S)rM)�idr�rG)r�r)s  r/r�zQTestComplexWorkflowPerformance.test_data_pipeline_performance.<locals>.<listcomp>2s$��C�C�C�!�1�q�1�u�-�-�C�C�Cr1c�B�g|]}tj|d����S)r�)rr)r��items  r/r�zQTestComplexWorkflowPerformance.test_data_pipeline_performance.<locals>.<listcomp>7s&��F�F�F�T�G�M�$�w�-�0�0�F�F�Fr1r;c��|Sr�rGrNs r/rPzOTestComplexWorkflowPerformance.test_data_pipeline_performance.<locals>.<lambda>=s��A�r1rc��|dzSrarGrcs  r/rPzOTestComplexWorkflowPerformance.test_data_pipeline_performance.<locals>.<lambda>Bs
��3��7�r1r5rr
�
total_elapsedrrrNrbrergrtrWrirlrmz
Data pipeline (z items):z  stage 1 (raw data): r	rSr�z  stage 2 (to patterns): z  stage 3 (transform): z  stage 4 (aggregate): z	  total: )rrrr6r>rUrnrrrrr r!r"r#r$)r&rW�stage1_start�raw_data�stage1_elapsed�stage2_startr��dataset�stage2_elapsed�stage3_startr��stage3_elapsed�stage4_startrt�stage4_elapsedr�r+r,r-r.rorprqs                       r/�test_data_pipeline_performancez=TestComplexWorkflowPerformance.test_data_pipeline_performance,s������y�{�{��C�C�u�T�{�{�C�C�C������|�3���y�{�{��F�F�X�F�F�F���/�&�'�*=�h�*G�*G�H�H������|�3���y�{�{���k�k�+�+�.�.������|�3���y�{�{��� � ��$:�$:�;�;������|�3��&��7�.�H�>�Y�
� #�"�}�s�"�"�"�"�"�"�"�"�"�"�}�s�"�"�"�"�"�"�"�"�"�"�"�"�}�"�"�"�"�"�}�"�"�"�"�"�"�s�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"� � ��q�� �u�� � � � � � � � � � �u�� � � � � � � � � � � � �u� � � � � �u� � � � � � � � � � � � � �� � � � � �� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � �
�0�$�0�0�0�1�1�1�
�B�~�d�':�B�B�B�B�C�C�C�
�E�.��*=�E�E�E�E�F�F�F�
�C��t�(;�C�C�C�C�D�D�D�
�C��t�(;�C�C�C�C�D�D�D�
�4�-��,�4�4�4�4�5�5�5�5�5r1N)rCrDrErFr�r�rGr1r/r�r�s9������:�:�%>�%>�%>�N%6�%6�%6�%6�%6r1r�c��eZdZdZd�Zd�ZdS)�TestMemoryEfficiencyz&Test memory efficiency (basic checks).c��d}tt|����}tjdtj|����}|j}|��}||k}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��dtj	��vst
j
|��rt
j|��ndd�z}dd	|iz}tt
j
|�����d
x}x}}|�d���}	|�d���}	|�d
d���}
d}||z}|
|k}|s�t
jd|fd|
|f��dtj	��vst
j
|
��rt
j|
��nddtj	��vst
j
|��rt
j|��ndt
j|��d�z}dd|iz}tt
j
|�����d
x}x}}t#d|�d���d
S)z0Verify large patterns don't cause memory issues.i�r;rer�rXrWr�r�r�Nc��|Sr�rGrNs r/rPz@TestMemoryEfficiency.test_large_pattern_memory.<locals>.<lambda>cs��A�r1c��dS�NTrGrNs r/rPz@TestMemoryEfficiency.test_large_pattern_memory.<locals>.<lambda>ds��t�r1rc��|dzSrarGrcs  r/rPz@TestMemoryEfficiency.test_large_pattern_memory.<locals>.<lambda>es
���q��r1rbrgrtrirlrmz
Large pattern memory test: z  elements processed successfully)r=rrr6r>r�rrrrr r!r"r#rUr]rnr$)
r&rWr@rXr,rorpr�r�r*rtr.rqs
             r/�test_large_pattern_memoryz.TestMemoryEfficiency.test_large_pattern_memoryWs������E�$�K�K� � ���O�F�G�$7��$=�$=�>�>���x�!�x�x�z�z�!�z�T�!�!�!�!�!�!�!�!�!�!�z�T�!�!�!�!�!�!�!�!�!�!�!�!�q�!�!�!�!�!�q�!�!�!�!�!�!�x�!�!�!�!�z�!�!�!�!�!�!�!�!�!�!�!�T�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�
�E�E�+�+����
�H�H�^�^�$�$�����q�0�0�1�1�� � ��q�� �u�� � � � � � � � � � �u�� � � � � � � � � � � � �u� � � � � �u� � � � � � � � � � � � � �� � � � � �� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � �
�T�d�T�T�T�U�U�U�U�Ur1c
�V��tjdtjtt	d��������}t	d��D]G�|��fd���}|�d���}|�dd���}�Htd��dS)	z3Verify patterns can be reused without memory leaks.r;r3c���|�zSr�rG)rOr)s �r/rPz9TestMemoryEfficiency.test_pattern_reuse.<locals>.<lambda>ps���1�q�5�r1c��dSr�rGrNs r/rPz9TestMemoryEfficiency.test_pattern_reuse.<locals>.<lambda>qs��d�r1rc��|dzSrarGrcs  r/rPz9TestMemoryEfficiency.test_pattern_reuse.<locals>.<lambda>rs
��C�!�G�r1z:
Pattern reuse test: 100 iterations completed successfullyN)	rr6r>r=rrUr]rnr$)r&�baser*r)s   @r/�test_pattern_reusez'TestMemoryEfficiency.test_pattern_reusejs������v�w�':�4��c�
�
�;K�;K�'L�'L�M�M���s���	5�	5�A��������)�)�A����N�N�+�+�A��	�	�!�3�3�4�4�A�A�	�L�M�M�M�M�Mr1N)rCrDrErFr�r�rGr1r/r�r�Ts@������0�0�V�V�V�&N�N�N�N�Nr1r��__main__z-vz-s)rF�builtinsr�_pytest.assertion.rewrite�	assertion�rewriterr�pytest�pattern_corerrrrrIrxr�r�r�rC�main�__file__rGr1r/�<module>r�s����������������������
�
�
�
�9�9�9�9�9�9�9�9�9�9�-o�-o�-o�-o�-o�-o�-o�-o�`9m�9m�9m�9m�9m�9m�9m�9m�x0|�0|�0|�0|�0|�0|�0|�0|�fR6�R6�R6�R6�R6�R6�R6�R6�jO6�O6�O6�O6�O6�O6�O6�O6�d!N�!N�!N�!N�!N�!N�!N�!N�H�z����F�K��4��&�'�'�'�'�'��r1