Last active
July 30, 2021 16:21
-
-
Save thuwarakeshm/4640f3f5707eb66b168d5a9c1e0b88c4 to your computer and use it in GitHub Desktop.
PyJS Comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 5000; | |
const fib = (n) => { | |
if (n < 2) return n; | |
return fib(n - 1) + fib(n - 2); | |
}; | |
app.get("/", (req, res) => { | |
res.send({ data: fib(30) }); | |
}); | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
def fib(n): | |
return n if n < 2 else fib(n - 1) + fib(n - 2) | |
@app.route("/") | |
def hello_world(): | |
return {"data": fib(30)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from multiprocessing import Pool | |
def fetch(i): | |
return requests.get("http://localhost:5000/").elapsed.microseconds | |
if __name__ == "__main__": | |
with Pool(10) as p: | |
res_times = p.map(fetch, list(range(1000))) | |
avg_time = sum(res_times) / len(res_times) if len(res_times) else 0 | |
print(f"On average each request took {round(avg_time/1000)} milliseconds.\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment