Add benchmark tool

This commit is contained in:
yhirose 2024-09-05 12:22:46 -04:00
parent b4989130da
commit c75d071615
6 changed files with 14388 additions and 0 deletions

3
.gitignore vendored
View file

@ -21,6 +21,8 @@ test/test.xcodeproj/*/xcuser*
test/*.o
test/*.pem
test/*.srl
benchmark/server
benchmark/server-crow
*.swp
@ -34,6 +36,7 @@ Release
*.db
ipch
*.dSYM
*.pyc
.*
!/.gitattributes
!/.travis.yml

31
benchmark/Makefile Normal file
View file

@ -0,0 +1,31 @@
CXXFLAGS = -std=c++14 -O2 -I..
THEAD_POOL_COUNT = 16
BENCH_FLAGS = -c 8 -d 5s
# cpp-httplib
bench: server
@./server & export PID=$$!; bombardier $(BENCH_FLAGS) localhost:8080; kill $${PID}
server : cpp-httplib/main.cpp ../httplib.h
g++ -o $@ $(CXXFLAGS) -DCPPHTTPLIB_THREAD_POOL_COUNT=$(THEAD_POOL_COUNT) cpp-httplib/main.cpp
run : server
@./server
# crow
server-crow : crow/main.cpp
g++ -o $@ $(CXXFLAGS) crow/main.cpp
bench-crow: server-crow
@./server-crow & export PID=$$!; bombardier $(BENCH_FLAGS) localhost:8080; kill $${PID}
# flask
bench-flask:
@FLASK_APP=flask/main.py flask run --port=8080 & export PID=$$!; bombardier $(BENCH_FLAGS) localhost:8080; kill $${PID}
# misc
bench-all: bench bench-crow bench-flask
clean:
rm -rf server*

View file

@ -0,0 +1,12 @@
#include "httplib.h"
using namespace httplib;
int main() {
Server svr;
svr.Get("/", [](const Request &, Response &res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("0.0.0.0", 8080);
}

14316
benchmark/crow/crow_all.h Normal file

File diff suppressed because it is too large Load diff

17
benchmark/crow/main.cpp Normal file
View file

@ -0,0 +1,17 @@
#include "crow_all.h"
class CustomLogger : public crow::ILogHandler {
public:
void log(std::string, crow::LogLevel) {}
};
int main() {
CustomLogger logger;
crow::logger::setHandler(&logger);
crow::SimpleApp app;
CROW_ROUTE(app, "/")([]() { return "Hello world!"; });
app.port(8080).multithreaded().run();
}

9
benchmark/flask/main.py Normal file
View file

@ -0,0 +1,9 @@
from flask import Flask
app = Flask(__name__)
import logging
logging.getLogger('werkzeug').disabled = True
@app.route('/')
def hello_world():
return 'Hello, World!'