Add basic http router benchmark
This commit is contained in:
+1
-7
@@ -134,7 +134,7 @@ private:
|
|||||||
inline std::pair<std::string_view, bool> getUrlSegment(int urlSegment) {
|
inline std::pair<std::string_view, bool> getUrlSegment(int urlSegment) {
|
||||||
if (urlSegment > urlSegmentTop) {
|
if (urlSegment > urlSegmentTop) {
|
||||||
/* Signal as STOP when we have no more URL or stack space */
|
/* 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};
|
return {{}, true};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,12 +292,6 @@ public:
|
|||||||
/* Alloate this handler */
|
/* Alloate this handler */
|
||||||
handlers.emplace_back(std::move(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 */
|
/* ANY method must be last, GET must be first */
|
||||||
std::sort(root.children.begin(), root.children.end(), [](const auto &a, const auto &b) {
|
std::sort(root.children.begin(), root.children.end(), [](const auto &a, const auto &b) {
|
||||||
/* Assuming the list of methods is unique, non-repeating */
|
/* Assuming the list of methods is unique, non-repeating */
|
||||||
|
|||||||
@@ -376,10 +376,36 @@ void testParameters() {
|
|||||||
assert(result == "GLWGPW");
|
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() {
|
int main() {
|
||||||
testPatternPriority();
|
testPatternPriority();
|
||||||
testMethodPriority();
|
testMethodPriority();
|
||||||
testUpgrade();
|
testUpgrade();
|
||||||
testBugReports();
|
testBugReports();
|
||||||
testParameters();
|
testParameters();
|
||||||
|
testPerformance();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ default:
|
|||||||
$(CXX) -std=c++17 -fsanitize=address HttpParser.cpp -o HttpParser
|
$(CXX) -std=c++17 -fsanitize=address HttpParser.cpp -o HttpParser
|
||||||
./HttpParser
|
./HttpParser
|
||||||
|
|
||||||
|
performance:
|
||||||
|
$(CXX) -std=c++17 HttpRouter.cpp -O3 -o HttpRouter
|
||||||
|
./HttpRouter
|
||||||
|
|
||||||
smoke:
|
smoke:
|
||||||
../Crc32 &
|
../Crc32 &
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|||||||
Reference in New Issue
Block a user