-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_rs_parallel.py
57 lines (43 loc) · 1.8 KB
/
handler_rs_parallel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from payment_handler_rs import PaymentHandlerParallel
import time
import cProfile
import os
import logging
import pandas as pd
from datetime import datetime
import joblib
from helpers import generate_random_seeds, generate_payments, setup_environment, initialize_profiler, log_time
import math
logging.basicConfig(
level=logging.INFO, # Set the logging level to INFO
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', # Log format
)
# Create a logger object
logger = logging.getLogger(__name__)
def main():
config = setup_environment()
profiler = initialize_profiler()
time_taken = []
for run_index in range(config['runs']):
logger.info("Loading payments")
payments = pd.read_parquet(f'artefacts/payments/payments_{run_index}.parquet').to_dict(orient='records')
logger.info(f"Starting run {run_index + 1}/{config['runs']}")
start_time = time.time()
profiler.enable()
payment_handler = PaymentHandlerParallel()
payment_handler.process_payments(
[(payment["merchant_id"], payment["amount"]) for payment in payments],
config['periodic_statistics_interval'],
config['periodic_statistics_window_size'],
config['confidence_interval'])
profiler.disable()
profiler.dump_stats(f"artefacts/rust_parallel/run_{run_index + 1}.prof")
end_time = time.time()
elapsed_time = log_time(start_time, end_time)
time_taken.append(elapsed_time)
joblib.dump(time_taken, 'artefacts/rust_parallel/time_taken.joblib')
logger.info(f"Average time taken: {sum(time_taken)/len(time_taken):.2f} seconds")
logger.info(f"Max time taken: {max(time_taken):.2f} seconds")
logger.info(f"Min time taken: {min(time_taken):.2f} seconds")
if __name__ == "__main__":
main()