From decd2b8c802d5e8d298b2a73849426cf4cd1759b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 14 Aug 2020 23:37:55 +0200 Subject: [PATCH] [sans-io] add minimal benchmarks --- test/mitmproxy/proxy2/bench.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/mitmproxy/proxy2/bench.py diff --git a/test/mitmproxy/proxy2/bench.py b/test/mitmproxy/proxy2/bench.py new file mode 100644 index 000000000..dc3b93784 --- /dev/null +++ b/test/mitmproxy/proxy2/bench.py @@ -0,0 +1,42 @@ +""" +Usage: + - pip install pytest-benchmark + - pytest bench.py + +See also: + - https://github.com/mitmproxy/proxybench +""" +import copy + +from .layers.http import test_http, test_http2 +from .layers import test_tcp, test_tls + + +def test_bench_http_roundtrip(tctx, benchmark): + # benchmark something + benchmark(test_http.test_http_proxy, tctx) + + +def test_bench_http2_roundtrip(tctx, benchmark): + # benchmark something + benchmark(test_http2.test_simple, tctx) + + +def test_bench_tcp_roundtrip(tctx, benchmark): + # benchmark something + benchmark(lambda: test_tcp.test_simple(copy.deepcopy(tctx))) + + +def test_bench_server_tls(tctx, benchmark): + t = test_tls.TestServerTLS().test_simple + benchmark(lambda: t(copy.deepcopy(tctx))) + + +def test_bench_client_tls(tctx, benchmark): + t = test_tls.TestClientTLS().test_client_only + benchmark(lambda: t(copy.deepcopy(tctx))) + + +def test_bench_tls_both(tctx, benchmark): + t = test_tls.TestClientTLS().test_server_required + benchmark(lambda: t(copy.deepcopy(tctx)))