Skip to content

Commit 7f00693

Browse files
committed
misc(examples): add cursor position query speed test
1 parent f737712 commit 7f00693

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/cursor-position-query.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "../tui.hpp"
2+
#include <cassert>
3+
#include <chrono>
4+
#include <cstdint>
5+
// #include <thread>
6+
7+
// returns how much the queries altogether took in ns
8+
uint64_t get_cursor_pos_n(const unsigned n) {
9+
auto start = std::chrono::high_resolution_clock::now();
10+
for (auto i = 0; i < n; ++i) {
11+
// std::cout << "getting cursor position...\n";
12+
auto cursor_pos = tui::cursor::get_position();
13+
// std::cout << "cursor @ {" << cursor_pos.first << ", " << cursor_pos.second << "}\n";
14+
// assert(cursor_pos == cursor_pos_tty);
15+
// std::this_thread::sleep_for(std::chrono::milliseconds(800));
16+
}
17+
auto end = std::chrono::high_resolution_clock::now();
18+
return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
19+
}
20+
21+
int main(int argc, char** argv) {
22+
tui::enable_raw_mode();
23+
24+
unsigned n = 8;
25+
if (argc > 1) {
26+
n = std::stoi(argv[1]);
27+
}
28+
29+
auto query_t_sum = get_cursor_pos_n(n);
30+
// std::this_thread::sleep_for(std::chrono::seconds(8));
31+
tui::disable_raw_mode();
32+
std::cout << "getting cursor " << n << " times took: " << query_t_sum / 1000000 << "ms, avg: " << query_t_sum / n <<"ns\n";
33+
return 0;
34+
}

0 commit comments

Comments
 (0)