Skip to content

Instantly share code, notes, and snippets.

@EpicEric
Last active November 19, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EpicEric/32db8a6e3a88308158bc1e85ef87b963 to your computer and use it in GitHub Desktop.
Save EpicEric/32db8a6e3a88308158bc1e85ef87b963 to your computer and use it in GitHub Desktop.
pony-http-benchmarks
$ ./pony-bench
Benchmark results will have their mean and median adjusted for overhead.
You may disable this with --noadjust.
Benchmark mean median deviation iterations
Official HTTP library parser 7718 ns 7694 ns ±1.60% 20000
Shetland parser 4433 ns 4427 ns ±1.58% 30000
----------------------------------------------------------
$ ./c-bench
2510 ns
/*
* Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase,
* Shigeo Mitsunari
*
* The software is licensed under either the MIT License (below) or the Perl
* license.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <assert.h>
#include <stdio.h>
#include <time.h>
#include "picohttpparser.h"
#define REQ \
"GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r\n" \
"Host: www.kittyhell.com\r\n" \
"User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 " \
"Pathtraq/0.9\r\n" \
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" \
"Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n" \
"Accept-Encoding: gzip,deflate\r\n" \
"Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n" \
"Keep-Alive: 115\r\n" \
"Connection: keep-alive\r\n" \
"Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; " \
"__utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; " \
"__utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral\r\n" \
"\r\n"
int main(void)
{
const char *method;
size_t method_len;
const char *path;
size_t path_len;
int minor_version;
struct phr_header headers[32];
size_t num_headers;
int i, ret;
clock_t start = clock(), diff;
for (i = 0; i < 10000000; i++) {
num_headers = sizeof(headers) / sizeof(headers[0]);
ret = phr_parse_request(REQ, sizeof(REQ) - 1, &method, &method_len, &path, &path_len, &minor_version, headers, &num_headers,
0);
assert(ret == sizeof(REQ) - 1);
}
diff = clock() - start;
printf("%lu ns\n", (diff * 100) / CLOCKS_PER_SEC);
return 0;
}
use "ponybench"
use "buffered"
use "debug"
use "./http/http"
use shetland = "./shetland/http"
primitive _Request
fun apply(): String =>
"GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r
Host: www.kittyhell.com\r
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Pathtraq/0.9\r
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r
Accept-Language: ja,en-us;q=0.7,en;q=0.3\r
Accept-Encoding: gzip,deflate\r
Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r
Keep-Alive: 115\r
Connection: keep-alive\r
Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; __utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; __utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral\r
\r\n"
actor _TestHTTPSession is HTTPSession
var _c: (AsyncBenchContinue | None) = None
be set_continue(c: AsyncBenchContinue) =>
_c = c
be apply(payload: Payload val) =>
Debug("apply")
be finish() =>
Debug("finish")
be dispose() =>
Debug("dispose")
be write(data: ByteSeq val) => None
be cancel(msg: Payload val) => None
be _mute() => None
be _unmute() => None
be _deliver(payload: Payload val) =>
Debug("_deliver")
match payload.transfer_mode
| OneshotTransfer =>
try
(_c as AsyncBenchContinue).complete()
else
Debug("no benchcontinue set")
end
else
Debug("_deliver chunk|stream")
end
be _chunk(data: ByteSeq val) =>
Debug("_chunk")
be _finish() => None
Debug("_finish")
try
(_c as AsyncBenchContinue).complete()
else
Debug("_finish None")
end
class _ParseRequestBenchmark
let _session: _TestHTTPSession = _TestHTTPSession.create()
let _parser: HTTPParser = HTTPParser.request(_session)
fun ref apply(c: AsyncBenchContinue, buffer: Reader) ? =>
_session.set_continue(c)
_parser.parse(buffer)?
actor Main is BenchmarkList
new create(env: Env) =>
PonyBench(env, this)
fun tag benchmarks(bench: PonyBench) =>
bench(_OfficialBench)
bench(_ShetlandBench)
class iso _OfficialBench is AsyncMicroBenchmark
let parse_bench: _ParseRequestBenchmark = _ParseRequestBenchmark
fun name(): String => "Official HTTP library parser"
fun ref apply(c: AsyncBenchContinue) ? =>
parse_bench(c, Reader .> append(_Request()))?
class iso _ShetlandBench is MicroBenchmark
let buffer: Reader = Reader .> append(_Request().array())
let request: Array[U8] val = _Request().array()
var header: (shetland.RawHttpRequest | None) = None
fun name(): String => "Shetland parser"
fun ref apply() ? =>
let eoh = shetland.HttpParser.end_of_headers(buffer)
header = shetland.HttpParser.parse_request(request, header) as shetland.RawHttpRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment