Add basic http router benchmark

This commit is contained in:
Alex Hultman
2023-12-19 06:00:33 +01:00
parent 53e835c1fa
commit 03c2997f2e
3 changed files with 31 additions and 7 deletions
+1 -7
View File
@@ -134,7 +134,7 @@ private:
inline std::pair<std::string_view, bool> getUrlSegment(int urlSegment) {
if (urlSegment > urlSegmentTop) {
/* Signal as STOP when we have no more URL or stack space */
if (!currentUrl.length() || urlSegment > 99) {
if (!currentUrl.length() || urlSegment > MAX_URL_SEGMENTS - 1) {
return {{}, true};
}
@@ -292,12 +292,6 @@ public:
/* Alloate this handler */
handlers.emplace_back(std::move(handler));
/* Assume can find this handler again */
if (((handlers.size() - 1) | priority) != findHandler(methods[0], pattern, priority)) {
std::cerr << "Error: Internal routing error" << std::endl;
std::abort();
}
/* ANY method must be last, GET must be first */
std::sort(root.children.begin(), root.children.end(), [](const auto &a, const auto &b) {
/* Assuming the list of methods is unique, non-repeating */
+26
View File
@@ -376,10 +376,36 @@ void testParameters() {
assert(result == "GLWGPW");
}
#include <chrono>
void testPerformance() {
std::cout << "TestPerformance" << std::endl;
uWS::HttpRouter<int> r;
r.add({"GET"}, "/*", [](auto *h) {
return true;
});
r.add({"*"}, "/*", [](auto *h) {
return true;
});
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < 1000000; i++) {
r.route("GET", "/something");
r.route("other", "/whatever");
}
auto end = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << "Duration: " << duration << "ms" << std::endl;
}
int main() {
testPatternPriority();
testMethodPriority();
testUpgrade();
testBugReports();
testParameters();
testPerformance();
}
+4
View File
@@ -14,6 +14,10 @@ default:
$(CXX) -std=c++17 -fsanitize=address HttpParser.cpp -o HttpParser
./HttpParser
performance:
$(CXX) -std=c++17 HttpRouter.cpp -O3 -o HttpRouter
./HttpRouter
smoke:
../Crc32 &
sleep 1