0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-30 19:25:12 -05:00
denoland-deno/tools/http_benchmark.py

56 lines
1.4 KiB
Python
Raw Normal View History

2018-10-15 16:44:35 -04:00
#!/usr/bin/env python
2018-10-20 03:25:29 +08:00
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
2018-10-15 16:44:35 -04:00
import os
import sys
import util
import time
import subprocess
ADDR = "127.0.0.1:4544"
DURATION = "10s"
def deno_http_benchmark(deno_exe):
2018-10-15 16:44:35 -04:00
deno_cmd = [deno_exe, "--allow-net", "tests/http_bench.ts", ADDR]
print "http_benchmark testing DENO."
return run(deno_cmd)
2018-10-15 16:44:35 -04:00
def node_http_benchmark(deno_exe):
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]]
2018-10-15 16:44:35 -04:00
print "http_benchmark testing NODE."
return run(node_cmd)
def http_benchmark(deno_exe):
deno_rps = deno_http_benchmark(deno_exe)
node_rps = node_http_benchmark(deno_exe)
2018-10-15 16:44:35 -04:00
return {"deno": deno_rps, "node": node_rps}
def run(server_cmd):
# Run deno echo server in the background.
server = subprocess.Popen(server_cmd)
time.sleep(5) # wait for server to wake up. TODO racy.
wrk_platform = {
"linux2": "linux",
"darwin": "mac",
}[sys.platform]
try:
cmd = "third_party/wrk/" + wrk_platform + "/wrk -d " + DURATION + " http://" + ADDR + "/"
print cmd
output = subprocess.check_output(cmd, shell=True)
req_per_sec = util.parse_wrk_output(output)
print output
return req_per_sec
finally:
server.kill()
if __name__ == '__main__':
if len(sys.argv) < 2:
2018-10-19 21:44:18 +09:00
print "Usage ./tools/http_benchmark.py out/debug/deno"
2018-10-15 16:44:35 -04:00
sys.exit(1)
deno_http_benchmark(sys.argv[1])