| 40 | using ::arrow::Compression; |
| 41 | |
| 42 | std::vector<uint8_t> MakeCompressibleData(int data_size) { |
| 43 | // XXX This isn't a real-world corpus so doesn't really represent the |
| 44 | // comparative qualities of the algorithms |
| 45 | |
| 46 | // First make highly compressible data |
| 47 | std::string base_data = |
| 48 | "Apache Arrow is a cross-language development platform for in-memory data"; |
| 49 | int nrepeats = static_cast<int>(1 + data_size / base_data.size()); |
| 50 | |
| 51 | std::vector<uint8_t> data(base_data.size() * nrepeats); |
| 52 | for (int i = 0; i < nrepeats; ++i) { |
| 53 | std::memcpy(data.data() + i * base_data.size(), base_data.data(), base_data.size()); |
| 54 | } |
| 55 | data.resize(data_size); |
| 56 | |
| 57 | // Then randomly mutate some bytes so as to make things harder |
| 58 | std::mt19937 engine(42); |
| 59 | std::exponential_distribution<> offsets(0.05); |
| 60 | std::uniform_int_distribution<> values(0, 255); |
| 61 | |
| 62 | int64_t pos = 0; |
| 63 | while (pos < data_size) { |
| 64 | data[pos] = static_cast<uint8_t>(values(engine)); |
| 65 | pos += static_cast<int64_t>(offsets(engine)); |
| 66 | } |
| 67 | |
| 68 | return data; |
| 69 | } |
| 70 | |
| 71 | // Using a non-zero copy buffer reader to benchmark the non-zero copy path. |
| 72 | class NonZeroCopyBufferReader final : public InputStream { |