Skip to content

Commit ce0f68f

Browse files
committed
test billiard
1 parent ae43889 commit ce0f68f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

libsast/core_matcher/pattern_matcher.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def read_file_contents(self, paths: list) -> list:
6262

6363
def regex_scan(self, file_contents: list) -> dict:
6464
"""Scan file(s) content."""
65+
import time
66+
from billiard import Pool
67+
start_time = time.time()
68+
6569
# Use a ProcessPool for CPU-bound regex
6670
with ProcessPoolExecutor(max_workers=self.cpu) as cpu_executor:
6771

@@ -70,6 +74,18 @@ def regex_scan(self, file_contents: list) -> dict:
7074
self.pattern_matcher,
7175
file_contents,
7276
)
77+
endtime = time.time()
78+
print(f"Execution ProcPool time: {endtime - start_time:.2f} seconds")
79+
80+
with Pool(processes=self.cpu) as cpu_pool:
81+
# Use billiard's map to distribute file_contents to self.pattern_matcher
82+
results = cpu_pool.map(
83+
self.pattern_matcher,
84+
file_contents,
85+
)
86+
endtime = time.time()
87+
print(f"Execution Billiard time: {endtime - start_time:.2f} seconds")
88+
start_time = time.time()
7389

7490
# Compile findings
7591
self.add_finding(results)

0 commit comments

Comments
 (0)