2018-10-11 16:55:22 -04:00
|
|
|
#!/usr/bin/env python
|
2020-01-21 10:01:55 -05:00
|
|
|
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2018-10-11 16:55:22 -04:00
|
|
|
# Performs benchmark and append data to //website/data.json.
|
2018-11-30 03:27:41 -05:00
|
|
|
# If //website/data.json doesn't exist, this script tries to import it from
|
|
|
|
# gh-pages branch.
|
2020-07-04 13:05:01 -04:00
|
|
|
# To view the results locally run target/debug/test_server and visit
|
2018-10-11 16:55:22 -04:00
|
|
|
# http://localhost:4545/website
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import subprocess
|
2019-09-11 16:47:42 -04:00
|
|
|
import util
|
2018-10-11 16:55:22 -04:00
|
|
|
|
|
|
|
MB = 1024 * 1024
|
2019-09-30 12:35:48 -04:00
|
|
|
SERVER_ADDR = "0.0.0.0:4544"
|
|
|
|
CLIENT_ADDR = "127.0.0.1 4544"
|
2018-10-11 16:55:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
def cat(deno_exe, megs):
|
|
|
|
size = megs * MB
|
|
|
|
start = time.time()
|
2019-05-03 17:15:16 -04:00
|
|
|
cmd = deno_exe + " run --allow-read "
|
2020-02-02 16:55:22 -05:00
|
|
|
cmd += "cli/tests/cat.ts /dev/zero | head -c %s " % size
|
2018-10-11 16:55:22 -04:00
|
|
|
print cmd
|
|
|
|
subprocess.check_output(cmd, shell=True)
|
|
|
|
end = time.time()
|
|
|
|
return end - start
|
|
|
|
|
|
|
|
|
|
|
|
def tcp(deno_exe, megs):
|
|
|
|
size = megs * MB
|
|
|
|
# Run deno echo server in the background.
|
2019-09-30 12:35:48 -04:00
|
|
|
args = [
|
2020-02-02 16:55:22 -05:00
|
|
|
deno_exe, "run", "--allow-net", "cli/tests/echo_server.ts", SERVER_ADDR
|
2019-09-30 12:35:48 -04:00
|
|
|
]
|
|
|
|
print args
|
|
|
|
echo_server = subprocess.Popen(args)
|
2018-10-11 16:55:22 -04:00
|
|
|
|
2018-10-15 16:54:51 -04:00
|
|
|
time.sleep(5) # wait for deno to wake up. TODO racy.
|
2018-10-11 16:55:22 -04:00
|
|
|
try:
|
|
|
|
start = time.time()
|
2019-09-30 12:35:48 -04:00
|
|
|
nc_cmd = "nc " + CLIENT_ADDR
|
|
|
|
cmd = ("head -c %s /dev/zero " % size) + " | " + nc_cmd
|
2018-10-11 16:55:22 -04:00
|
|
|
print cmd
|
|
|
|
subprocess.check_output(cmd, shell=True)
|
|
|
|
end = time.time()
|
|
|
|
return end - start
|
|
|
|
finally:
|
|
|
|
echo_server.kill()
|
|
|
|
|
|
|
|
|
2018-11-30 03:27:41 -05:00
|
|
|
def main():
|
2018-10-11 16:55:22 -04:00
|
|
|
deno_exe = sys.argv[1]
|
|
|
|
megs = int(sys.argv[2])
|
|
|
|
if not deno_exe or not megs:
|
2018-11-08 13:38:20 -05:00
|
|
|
print "Usage ./tools/throughput_benchmark.py target/debug/deno 100"
|
2018-10-11 16:55:22 -04:00
|
|
|
sys.exit(1)
|
2018-10-15 16:54:51 -04:00
|
|
|
secs = tcp(sys.argv[1], megs)
|
2018-10-11 16:55:22 -04:00
|
|
|
print secs, "seconds"
|
2018-11-30 03:27:41 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|