File size: 721 Bytes
d278e8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
import math
import time

app = FastAPI()

@app.get("/")
def read_root():
    return {"status": "awake", "message": "The 16GB Engine is hot."}

@app.get("/heavy-math")
def do_heavy_math():
    start_time = time.time()
    
    primes = []
    for num in range(2, 50000):
        is_prime = True
        for i in range(2, int(math.sqrt(num)) + 1):
            if (num % i) == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(num)
            
    end_time = time.time()
    
    return {
        "message": "Heavy job complete in Python",
        "primes_found": len(primes),
        "seconds_taken": round(end_time - start_time, 2)
    }