MCPcopy Create free account
hub / github.com/apache/arrow / MakeRandomByteArray

Method MakeRandomByteArray

cpp/src/parquet/encoding_benchmark.cc:920–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

918 prefixed_probability(state.range(2) / 100.0) {}
919
920 std::vector<ByteArray> MakeRandomByteArray(uint32_t seed) {
921 std::default_random_engine gen(seed);
922 std::uniform_int_distribution<int> dist_size(min_size, max_size);
923 std::uniform_int_distribution<int> dist_byte(0, 255);
924 std::bernoulli_distribution dist_has_prefix(prefixed_probability);
925 std::uniform_real_distribution<double> dist_prefix_length(0, 1);
926
927 std::vector<ByteArray> out(array_length);
928 buf.resize(max_size * array_length);
929 auto buf_ptr = buf.data();
930 total_data_size = 0;
931
932 for (int32_t i = 0; i < array_length; ++i) {
933 int len = dist_size(gen);
934 out[i].len = len;
935 out[i].ptr = buf_ptr;
936
937 bool do_prefix = i > 0 && dist_has_prefix(gen);
938 int prefix_len = 0;
939 if (do_prefix) {
940 int max_prefix_len = std::min(len, static_cast<int>(out[i - 1].len));
941 prefix_len =
942 static_cast<int>(std::ceil(max_prefix_len * dist_prefix_length(gen)));
943 }
944 for (int j = 0; j < prefix_len; ++j) {
945 buf_ptr[j] = out[i - 1].ptr[j];
946 }
947 for (int j = prefix_len; j < len; ++j) {
948 buf_ptr[j] = static_cast<uint8_t>(dist_byte(gen));
949 }
950 buf_ptr += len;
951 total_data_size += len;
952 }
953 return out;
954 }
955};
956
957static void BM_DeltaEncodingByteArray(benchmark::State& state) {

Callers 2

Calls 2

resizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected