This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
remote_lat.cpp
61 lines (50 loc) · 1.78 KB
/
remote_lat.cpp
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
/*
Copyright (C) 2010 Erik Rigtorp <[email protected]>.
All rights reserved.
This file is part of NanoMQ.
NanoMQ is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NanoMQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NanoMQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <errno.h>
#include <cstdlib>
#include <nmq.hpp>
int main(int argc, char* argv[]) {
if (argc != 4) {
printf ("usage: remote_lat <queue> <message-size> "
"<roundtrip-count>\n");
return 1;
}
const char* queue = argv[1];
size_t message_size = atoi(argv [2]);
int roundtrip_count = atoi(argv [3]);
nmq::context_t context(queue);
if (!context.open(2, 15, message_size)) {
printf("error in context open: %s\n", strerror(errno));
return -1;
}
char *s = (char*)malloc(message_size);
if (s == NULL) {
printf("error in malloc: %s\n", strerror(errno));
return -1;
}
nmq::node_t node(context, 1);
struct timeval start, stop;
gettimeofday(&start, NULL);
for (int i = 0; i != roundtrip_count; i++) {
node.send(0, s, message_size);
node.recv(0, s, &message_size);
}
gettimeofday(&stop, NULL);
long delta = (stop.tv_sec - start.tv_sec)*1000000 + (stop.tv_usec - start.tv_usec);
long lat = (delta * 1000) / roundtrip_count;
printf("%li ns\n", lat);
}