-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (22 loc) · 813 Bytes
/
app.py
File metadata and controls
30 lines (22 loc) · 813 Bytes
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
from flask import Flask, jsonify
import time
import math
import os
app = Flask(__name__)
ITERATIONS = 30_000_000
def cpu_intensive_task(iterations):
start_time = time.time()
result = 0
for i in range(1, iterations + 1):
result += math.log(i + 1e-9)
end_time = time.time()
duration = end_time - start_time
return {"result_sum": result, "duration_seconds": duration, "iterations_performed": iterations}
@app.route('/process', methods=['GET'])
def process_request():
data = cpu_intensive_task(ITERATIONS)
print(f"Task took {data['duration_seconds']:.4f}s for {data['iterations_performed']} iterations.")
return jsonify(data)
if __name__ == '__main__':
port = int(os.environ.get("PORT", 8000))
app.run(host='0.0.0.0', port=port)