mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Add benchmark tool
This commit is contained in:
parent
b4989130da
commit
c75d071615
6 changed files with 14388 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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
31
benchmark/Makefile
Normal 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*
|
12
benchmark/cpp-httplib/main.cpp
Normal file
12
benchmark/cpp-httplib/main.cpp
Normal 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
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
17
benchmark/crow/main.cpp
Normal 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
9
benchmark/flask/main.py
Normal 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!'
|
Loading…
Reference in a new issue