NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
parser_perf.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011, Peter Thorson. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
* * Redistributions of source code must retain the above copyright
7
* notice, this list of conditions and the following disclaimer.
8
* * Redistributions in binary form must reproduce the above copyright
9
* notice, this list of conditions and the following disclaimer in the
10
* documentation and/or other materials provided with the distribution.
11
* * Neither the name of the WebSocket++ Project nor the
12
* names of its contributors may be used to endorse or promote products
13
* derived from this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*
26
*/
27
28
#include <
websocketpp/http/parser.hpp
>
29
30
#include <chrono>
31
32
class
scoped_timer
{
33
public
:
34
scoped_timer
(std::string i) : m_id(i),m_start(
std
::
chrono
::steady_clock::now()) {
35
std::cout <<
"Clock "
<< i <<
": "
;
36
}
37
~scoped_timer
() {
38
std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start;
39
40
//nanoseconds_per_test
41
42
//tests_per_second
43
44
//1000000000.0/(double(time_taken.count())/1000.0)
45
46
std::cout << 1000000000.0/(double(time_taken.count())/1000.0) << std::endl;
47
48
//std::cout << (1.0/double(time_taken.count())) * double(1000000000*1000) << std::endl;
49
}
50
51
private
:
52
std::string m_id;
53
std::chrono::steady_clock::time_point m_start;
54
};
55
56
int
main
() {
57
std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"
;
58
59
std::string firefox =
"GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"
;
60
61
std::string firefox1 =
"GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\n"
;
62
63
std::string firefox2 =
"Accept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n"
;
64
65
{
66
scoped_timer
timer(
"Simplest 1 chop"
);
67
for
(
int
i = 0; i < 1000; i++) {
68
websocketpp::http::parser::request
r;
69
70
try
{
71
r.
consume
(raw.c_str(),raw.size());
72
}
catch
(...) {
73
std::cout <<
"exception"
<< std::endl;
74
}
75
76
if
(!r.
ready
()) {
77
std::cout <<
"error"
<< std::endl;
78
break
;
79
}
80
}
81
}
82
83
{
84
scoped_timer
timer(
"FireFox, 1 chop, consume old"
);
85
for
(
int
i = 0; i < 1000; i++) {
86
websocketpp::http::parser::request
r;
87
88
try
{
89
r.consume2(firefox.c_str(),firefox.size());
90
}
catch
(...) {
91
std::cout <<
"exception"
<< std::endl;
92
}
93
94
if
(!r.
ready
()) {
95
std::cout <<
"error"
<< std::endl;
96
break
;
97
}
98
}
99
}
100
101
{
102
scoped_timer
timer(
"FireFox, 1 chop"
);
103
for
(
int
i = 0; i < 1000; i++) {
104
websocketpp::http::parser::request
r;
105
106
try
{
107
r.
consume
(firefox.c_str(),firefox.size());
108
}
catch
(...) {
109
std::cout <<
"exception"
<< std::endl;
110
}
111
112
if
(!r.
ready
()) {
113
std::cout <<
"error"
<< std::endl;
114
break
;
115
}
116
}
117
}
118
119
120
121
{
122
scoped_timer
timer(
"FireFox, 2 chop"
);
123
for
(
int
i = 0; i < 1000; i++) {
124
websocketpp::http::parser::request
r;
125
126
try
{
127
r.
consume
(firefox1.c_str(),firefox1.size());
128
r.
consume
(firefox2.c_str(),firefox2.size());
129
}
catch
(...) {
130
std::cout <<
"exception"
<< std::endl;
131
}
132
133
if
(!r.
ready
()) {
134
std::cout <<
"error"
<< std::endl;
135
break
;
136
}
137
}
138
}
139
140
return
0;
141
}
std
STL namespace.
scoped_timer
Definition:
parser_perf.cpp:32
scoped_timer::scoped_timer
scoped_timer(std::string i)
Definition:
parser_perf.cpp:34
boost::chrono
Definition:
time.cpp:211
parser.hpp
scoped_timer::~scoped_timer
~scoped_timer()
Definition:
parser_perf.cpp:37
websocketpp::http::parser::request
Stores, parses, and manipulates HTTP requests.
Definition:
request.hpp:50
websocketpp::http::parser::request::consume
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
Definition:
request.hpp:41
main
int main()
Definition:
parser_perf.cpp:56
websocketpp::http::parser::request::ready
bool ready() const
Returns whether or not the request is ready for reading.
Definition:
request.hpp:82
ndnSIM
NFD
websocketpp
test
http
parser_perf.cpp
Generated on Thu Nov 2 2017 03:30:29 for ndnSIM by
1.8.11