// Copyright 2022 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #include #include #include "absl/strings/escaping.h" #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/decode_huff.h" #include "src/core/lib/gprpp/no_destruct.h" #include "src/core/lib/slice/slice.h" #include "test/core/test_util/test_config.h" #include "test/cpp/microbenchmarks/huffman_geometries/index.h" std::vector MakeInput(int min, int max) { std::vector v; std::uniform_int_distribution<> distribution(min, max); static std::mt19937 rd(0); v.reserve(1024 * 1024); for (int i = 0; i < 1024 * 1024; i++) { v.push_back(distribution(rd)); } grpc_core::Slice s = grpc_core::Slice::FromCopiedBuffer(v); grpc_core::Slice c(grpc_chttp2_huffman_compress(s.c_slice())); return std::vector(c.begin(), c.end()); } std::vector MakeBase64() { auto src = MakeInput(0, 255); auto s = absl::Base64Escape( absl::string_view(reinterpret_cast(src.data()), src.size())); return std::vector(s.begin(), s.end()); } const std::vector& AllChars() { static const auto* const data = new std::vector(MakeInput(0, 255)); return *data; }; const std::vector& AsciiChars() { static const auto* const data = new std::vector(MakeInput(32, 126)); return *data; }; const std::vector& AlphaChars() { static const auto* const data = new std::vector(MakeInput('a', 'z')); return *data; }; const std::vector& Base64Chars() { static const auto* const data = new std::vector(MakeBase64()); return *data; }; using CharSet = const std::vector& (*)(); template