-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
66 lines (55 loc) · 1.54 KB
/
benchmark.cpp
File metadata and controls
66 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Created by Rakesh on 16/03/2022.
//
#include <iostream>
#include "../src/router.hpp"
using namespace std::string_literals;
using namespace std::string_view_literals;
int main()
{
struct Request
{
int routed{ 0 };
};
spt::http::router::HttpRouter<Request *, bool> r;
Request request;
r.add( "GET"s, "/service/candy/{kind}", [](Request *user, auto&& /* args */) {
user->routed++;
return true;
} );
r.add( "GET"s, "/service/shutdown", [](Request *user, auto&& /* args */) {
user->routed++;
return true;
} );
r.add( "GET"s, "/", [](Request *user, auto&& /* args */) {
user->routed++;
return true;
} );
r.add( "GET"s, "/{filename}", [](Request *user, auto&& /* args */) {
user->routed++;
return true;
} );
// run benchmark of various urls
std::vector<std::string> urls = {
"/service/candy/lollipop",
"/service/candy/gum",
"/service/candy/seg_råtta",
"/service/candy/lakrits",
"/service/shutdown",
"/",
"/some_file.html",
"/another_file.jpeg"
};
for ( auto&& url : urls )
{
auto start = std::chrono::high_resolution_clock::now();
for ( int i = 0; i < 10000000; ++i )
{
r.route( "GET"s, url, &request );
}
auto stop = std::chrono::high_resolution_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count();
std::cout << "[" << (10000.0 / ms) << " million req/sec] for URL: " << url << std::endl;
}
std::cout << "Checksum: " << request.routed << std::endl << std::endl;
}