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

Function MakeCompressibleData

cpp/src/arrow/util/compression_benchmark.cc:38–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36#ifdef ARROW_WITH_BENCHMARKS_REFERENCE
37
38std::vector<uint8_t> MakeCompressibleData(int data_size) {
39 // XXX This isn't a real-world corpus so doesn't really represent the
40 // comparative qualities of the algorithms
41
42 // First make highly compressible data
43 std::string base_data =
44 "Apache Arrow is a cross-language development platform for in-memory data";
45 int nrepeats = static_cast<int>(1 + data_size / base_data.size());
46
47 std::vector<uint8_t> data(base_data.size() * nrepeats);
48 for (int i = 0; i < nrepeats; ++i) {
49 std::memcpy(data.data() + i * base_data.size(), base_data.data(), base_data.size());
50 }
51 data.resize(data_size);
52
53 // Then randomly mutate some bytes so as to make things harder
54 std::mt19937 engine(42);
55 std::exponential_distribution<> offsets(0.05);
56 std::uniform_int_distribution<> values(0, 255);
57
58 int64_t pos = 0;
59 while (pos < data_size) {
60 data[pos] = static_cast<uint8_t>(values(engine));
61 pos += static_cast<int64_t>(offsets(engine));
62 }
63
64 return data;
65}
66
67int64_t StreamingCompress(Codec* codec, const std::vector<uint8_t>& data,
68 std::vector<uint8_t>* compressed_data = nullptr) {

Callers 4

ReferenceCompressionFunction · 0.70
ReferenceDecompressionFunction · 0.70

Calls 5

resizeMethod · 0.80
valuesFunction · 0.50
offsetsFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected