Skip to content

Commit 4d741f4

Browse files
vvfedorenkofacebook-github-bot
authored andcommitted
Performance test
Summary: This code runs fbclock_gettime one million times and show the histogram of execution time based on monotonic clock Reviewed By: t3lurid3 Differential Revision: D60291089 fbshipit-source-id: e0c14d490a1b5d08fb730bc2337ae75c877a0331
1 parent 8daa74c commit 4d741f4

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#include <chrono>
4+
#include <iostream>
5+
#include <vector>
6+
#include "time/fbclock/fbclock.h"
7+
8+
int main() {
9+
std::vector<uint32_t>
10+
time_histogram; // create a histogramm of call time in us
11+
12+
time_histogram.resize(1001, 0);
13+
fbclock_lib fbclock = {};
14+
int res = fbclock_init(&fbclock, FBCLOCK_PATH);
15+
if (res != 0) {
16+
std::cout << "Failed to init fbclock library: errno " << res << std::endl;
17+
exit(0);
18+
}
19+
for (int i = 0; i < 1000000; i++) {
20+
fbclock_truetime true_time = {};
21+
auto start_time = std::chrono::steady_clock::now();
22+
fbclock_gettime_utc(&fbclock, &true_time);
23+
auto end_time = std::chrono::steady_clock::now();
24+
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
25+
end_time - start_time);
26+
if (duration.count() >= 1000)
27+
time_histogram[1000]++;
28+
else
29+
time_histogram[duration.count()]++;
30+
if (true_time.earliest_ns + 10000 <= true_time.latest_ns)
31+
std::cout << "WoU is more than 10us [" << true_time.earliest_ns << ","
32+
<< true_time.latest_ns << "] " << std::endl;
33+
}
34+
std::cout << "Histogram of query time:" << std::endl;
35+
for (int i = 0; i < 1001; i++) {
36+
if (time_histogram[i])
37+
std::cout << i << "us: " << time_histogram[i] << std::endl;
38+
}
39+
fbclock_destroy(&fbclock);
40+
}

0 commit comments

Comments
 (0)