From c54f75a909b07517c7df092036fbb1526c8129e3 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sat, 10 Jul 2021 09:56:09 -0700 Subject: [PATCH] :racehorse: result_buffer is faster when local --- src/user_filter.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/user_filter.cpp b/src/user_filter.cpp index d40789c..f6ffda7 100644 --- a/src/user_filter.cpp +++ b/src/user_filter.cpp @@ -3,6 +3,47 @@ template UserFilter::UserFilter(Bank &b) : bank(b) {} +#define time_func_a(f, a, x) \ + { \ + using namespace std::chrono; \ + uint32_t timer = 0; \ + for (int i = 0; i < x; ++i) \ + { \ + auto t1 = high_resolution_clock::now().time_since_epoch(); \ + f; \ + auto t2 = high_resolution_clock::now().time_since_epoch(); \ + a; \ + timer += std::chrono::duration_cast((t2 - t1)).count(); \ + } \ + std::cout << timer / x << '\n'; \ + } + +#define time_func(f, x) \ + { \ + using namespace std::chrono; \ + uint32_t timer = 0; \ + for (int i = 0; i < x; ++i) \ + { \ + auto t1 = high_resolution_clock::now().time_since_epoch(); \ + f; \ + auto t2 = high_resolution_clock::now().time_since_epoch(); \ + timer += std::chrono::duration_cast((t2 - t1)).count(); \ + } \ + std::cout << timer / x << '\n'; \ + } + +#define Op_a(v, name, x, a) \ + { \ + std::cout << name; \ + time_func_a(v, a, x); \ + } + +#define Op(v, name, x) \ + { \ + std::cout << name; \ + time_func(v, x); \ + } + template void UserFilter::doFilter(const HttpRequestPtr &req, FilterCallback &&fcb, @@ -14,7 +55,7 @@ void UserFilter::doFilter(const HttpRequestPtr &re if (auth_header.substr(0, 6) == "Basic ") { std::string_view base64_input = auth_header.substr(6); - static thread_local char result_buffer[max_name_size + 256]; //(username + ':' + 255 password) + char result_buffer[max_name_size + 256]; //(username + ':' + 255 password) std::memset(result_buffer, 0, max_name_size + 256); size_t new_sz; base64_decode(base64_input.data(), base64_input.size(), result_buffer, &new_sz, 0);