Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wall time in throughput test #91

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions examples/universal/z_sub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//
#include <stdio.h>
#include <time.h>
#include <chrono>

#include "../getargs.h"
#include "zenoh.hxx"
Expand All @@ -23,35 +23,37 @@ using namespace zenoh;
struct Stats {
volatile unsigned long count = 0;
volatile unsigned long finished_rounds = 0;
volatile clock_t start = 0;
volatile clock_t stop = 0;
volatile clock_t end = 0;
volatile clock_t first_start = 0;
std::chrono::steady_clock::time_point start = {};
std::chrono::steady_clock::time_point first_start = {};
std::chrono::steady_clock::time_point end = {};

void operator()(const Sample &) {
if (count == 0) {
start = clock();
if (!first_start) {
start = std::chrono::steady_clock::now();
if (first_start == std::chrono::steady_clock::time_point()) {
first_start = start;
}
count++;
} else if (count < N) {
count++;
} else {
stop = clock();
finished_rounds++;
printf("%f msg/s\n", N * (double)CLOCKS_PER_SEC / (double)(stop - start));
auto elapsed_us =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count();
std::cout << static_cast<double>(N) * 1000000.0 / static_cast<double>(elapsed_us) << " msg/s\n";
count = 0;
}
}

void operator()() { end = clock(); }
void operator()() { end = std::chrono::steady_clock::now(); }

void print() const {
const double elapsed = (double)(end - first_start) / (double)CLOCKS_PER_SEC;
auto elapsed_s =
static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(end - first_start).count()) /
1000000.0;
const unsigned long sent_messages = N * finished_rounds + count;
printf("Sent %ld messages over %f seconds (%f msg/s)\n", sent_messages, elapsed,
(double)sent_messages / elapsed);
std::cout << "Sent " << sent_messages << " messages over " << elapsed_s << " seconds ("
<< static_cast<double>(sent_messages) / elapsed_s << " msg/s)\n";
}
};

Expand Down
Loading