diff --git a/src/HttpRouter.h b/src/HttpRouter.h index b1c8f2c..175d858 100644 --- a/src/HttpRouter.h +++ b/src/HttpRouter.h @@ -134,7 +134,7 @@ private: inline std::pair 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 */ diff --git a/tests/HttpRouter.cpp b/tests/HttpRouter.cpp index 6dfa7b6..531746c 100644 --- a/tests/HttpRouter.cpp +++ b/tests/HttpRouter.cpp @@ -376,10 +376,36 @@ void testParameters() { assert(result == "GLWGPW"); } +#include + +void testPerformance() { + std::cout << "TestPerformance" << std::endl; + uWS::HttpRouter 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(end - start).count(); + std::cout << "Duration: " << duration << "ms" << std::endl; +} + int main() { testPatternPriority(); testMethodPriority(); testUpgrade(); testBugReports(); testParameters(); + testPerformance(); } diff --git a/tests/Makefile b/tests/Makefile index 1883fd9..d574145 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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