File tree Expand file tree Collapse file tree 3 files changed +43
-7
lines changed Expand file tree Collapse file tree 3 files changed +43
-7
lines changed Original file line number Diff line number Diff line change 1
1
2
2
CC = clang++
3
3
CFLAGS = -std=c++14 -I..
4
- OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lssl -lcrypto
4
+ # OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lssl -lcrypto
5
5
6
- all : server client hello simplesvr
6
+ all : server client hello simplesvr benchmark
7
7
8
- server : server.cc ../httplib.h
8
+ server : server.cc ../httplib.h Makefile
9
9
$(CC ) -o server $(CFLAGS ) server.cc $(OPENSSL_SUPPORT )
10
10
11
- client : client.cc ../httplib.h
11
+ client : client.cc ../httplib.h Makefile
12
12
$(CC ) -o client $(CFLAGS ) client.cc $(OPENSSL_SUPPORT )
13
13
14
- hello : hello.cc ../httplib.h
14
+ hello : hello.cc ../httplib.h Makefile
15
15
$(CC ) -o hello $(CFLAGS ) hello.cc $(OPENSSL_SUPPORT )
16
16
17
- simplesvr : simplesvr.cc ../httplib.h
17
+ simplesvr : simplesvr.cc ../httplib.h Makefile
18
18
$(CC ) -o simplesvr $(CFLAGS ) simplesvr.cc $(OPENSSL_SUPPORT )
19
19
20
+ benchmark : benchmark.cc ../httplib.h Makefile
21
+ $(CC ) -o benchmark $(CFLAGS ) benchmark.cc $(OPENSSL_SUPPORT )
22
+
20
23
pem :
21
24
openssl genrsa 2048 > key.pem
22
25
openssl req -new -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
Original file line number Diff line number Diff line change
1
+ #include < httplib.h>
2
+ #include < chrono>
3
+ #include < iostream>
4
+
5
+ using namespace std ;
6
+
7
+ struct StopWatch {
8
+ StopWatch (const string& label) : label_(label) {
9
+ start_ = chrono::system_clock::now ();
10
+ }
11
+ ~StopWatch () {
12
+ auto end = chrono::system_clock::now ();
13
+ auto diff = end - start_;
14
+ auto count = chrono::duration_cast<chrono::milliseconds>(diff).count ();
15
+ cout << label_ << " : " << count << " millisec." << endl;
16
+ }
17
+ string label_;
18
+ chrono::system_clock::time_point start_;
19
+ };
20
+
21
+ int main (int argc, char * argv[]) {
22
+ string body (1024 * 5 , ' a' );
23
+
24
+ httplib::Client cli (" httpbin.org" , 80 );
25
+
26
+ for (int i = 0 ; i < 3 ; i++) {
27
+ StopWatch sw (to_string (i).c_str ());
28
+ auto res = cli.post (" /post" , body, " application/octet-stream" );
29
+ assert (res->status == 200 );
30
+ }
31
+
32
+ return 0 ;
33
+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ CFLAGS = -std=c++14 -DGTEST_USE_OWN_TR1_TUPLE -I.. -I.
6
6
all : test
7
7
./test
8
8
9
- test : test.cc ../httplib.h
9
+ test : test.cc ../httplib.h Makefile
10
10
$(CC ) -o test $(CFLAGS ) test.cc gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT )
11
11
12
12
pem :
You can’t perform that action at this time.
0 commit comments