File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import numpy as np
44
5- from downsample import largest_triangle_three_buckets
5+ from downsample import lttb , ltob , ltd
66
7+ import pytest
78
8- def test_memory_leak ():
9+
10+ @pytest .mark .parametrize ("func" , [lttb , ltob ])
11+ def test_memory_leak (func ):
12+ """
13+ Test memory leak for different LTTB functions.
14+
15+ Args:
16+ func (callable): The function to test.
17+ """
918 tracemalloc .start ()
1019
20+ # Test parameters (shared for all functions)
1121 size = 1_000_000
22+ threshold = 100
23+ iterations = 1_000
24+
25+ # Generate test data
1226 x = np .linspace (0 , 10 , size )
1327 y = np .sin (x )
14- threshold = 100
1528
29+ # Snapshot before function execution
1630 before_snapshot = tracemalloc .take_snapshot ()
1731
18- for _ in range (1_000 ):
19- result = largest_triangle_three_buckets (x , y , threshold )
32+ for _ in range (iterations ):
33+ result = func (x , y , threshold )
2034 del result
2135 import gc
2236 gc .collect ()
2337
38+ # Snapshot after function execution
2439 after_snapshot = tracemalloc .take_snapshot ()
2540 tracemalloc .stop ()
2641
42+ # Calculate memory usage
2743 before_size = sum (
2844 stat .size for stat in before_snapshot .statistics ("filename" ))
2945 after_size = sum (
You can’t perform that action at this time.
0 commit comments