-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
550 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// 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 <DataTypes/DataTypeString.h> | ||
#include <IO/Buffer/ReadBufferFromString.h> | ||
#include <IO/Buffer/WriteBufferFromString.h> | ||
#include <Poco/UUIDGenerator.h> | ||
#include <TestUtils/FunctionTestUtils.h> | ||
#include <TestUtils/TiFlashTestBasic.h> | ||
#include <benchmark/benchmark.h> | ||
|
||
namespace DB::bench | ||
{ | ||
|
||
String getStreamName(const String & column_name, const IDataType::SubstreamPath & substream_path) | ||
{ | ||
return IDataType::getFileNameForStream(column_name, substream_path); | ||
} | ||
|
||
String randomString(size_t str_size) | ||
{ | ||
auto s = Poco::UUIDGenerator().createRandom().toString(); | ||
while (s.size() < str_size) | ||
{ | ||
s += Poco::UUIDGenerator().createRandom().toString(); | ||
} | ||
return s.substr(str_size); | ||
} | ||
|
||
ColumnPtr createColumnString(size_t str_size, size_t count) | ||
{ | ||
auto gen = Poco::UUIDGenerator(); | ||
std::vector<String> v(count); | ||
for (size_t i = 0; i < v.size(); ++i) | ||
{ | ||
v[i] = randomString(str_size); | ||
} | ||
return DB::tests::createColumn<String>(v, "", 0).column; | ||
} | ||
|
||
auto initWriteStream(IDataType & type) | ||
{ | ||
std::unordered_map<String, std::unique_ptr<WriteBufferFromOwnString>> write_streams; | ||
auto create_write_stream = [&](const IDataType::SubstreamPath & substream_path) { | ||
const auto stream_name = getStreamName("bench", substream_path); | ||
write_streams.emplace(stream_name, std::make_unique<WriteBufferFromOwnString>(100 * 1024 * 1024)); | ||
}; | ||
type.enumerateStreams(create_write_stream, {}); | ||
return write_streams; | ||
} | ||
|
||
constexpr size_t str_count = 65535; | ||
|
||
template <typename... Args> | ||
void serialize(benchmark::State & state, Args &&... args) | ||
{ | ||
auto [version, str_size] = std::make_tuple(std::move(args)...); | ||
auto str_col = createColumnString(str_size, str_count); | ||
DataTypeString t(version); | ||
IDataType & type = t; | ||
auto write_streams = initWriteStream(type); | ||
auto get_write_stream = [&](const IDataType::SubstreamPath & substream_path) { | ||
const auto stream_name = getStreamName("bench", substream_path); | ||
auto * write_stream = write_streams.at(stream_name).get(); | ||
write_stream->restart(); // Reset to avoid write buffer overflow. | ||
return write_stream; | ||
}; | ||
for (auto _ : state) | ||
{ | ||
type.serializeBinaryBulkWithMultipleStreams(*str_col, get_write_stream, 0, str_col->size(), true, {}); | ||
} | ||
} | ||
|
||
template <typename... Args> | ||
void deserialize(benchmark::State & state, Args &&... args) | ||
{ | ||
auto [version, str_size] = std::make_tuple(std::move(args)...); | ||
auto str_col = createColumnString(str_size, str_count); | ||
DataTypeString t(version); | ||
IDataType & type = t; | ||
auto write_streams = initWriteStream(type); | ||
auto get_write_stream = [&](const IDataType::SubstreamPath & substream_path) { | ||
const auto stream_name = getStreamName("bench", substream_path); | ||
auto * write_stream = write_streams.at(stream_name).get(); | ||
return write_stream; | ||
}; | ||
type.serializeBinaryBulkWithMultipleStreams(*str_col, get_write_stream, 0, str_col->size(), true, {}); | ||
|
||
std::unordered_map<String, std::unique_ptr<ReadBuffer>> read_streams; | ||
auto get_read_stream = [&](const IDataType::SubstreamPath & substream_path) { | ||
auto * write_stream = get_write_stream(substream_path); | ||
const auto stream_name = getStreamName("bench", substream_path); | ||
read_streams[stream_name] = std::make_unique<ReadBufferFromString>(write_stream->stringRef().toStringView()); | ||
return read_streams[stream_name].get(); | ||
}; | ||
for (auto _ : state) | ||
{ | ||
auto col = type.createColumn(); | ||
type.deserializeBinaryBulkWithMultipleStreams(*col, get_read_stream, 65535, 8, true, {}); | ||
benchmark::DoNotOptimize(col); | ||
} | ||
} | ||
|
||
BENCHMARK_CAPTURE(serialize, v0_size8, 0, 8); | ||
BENCHMARK_CAPTURE(serialize, v0_size16, 0, 16); | ||
BENCHMARK_CAPTURE(serialize, v0_size32, 0, 32); | ||
BENCHMARK_CAPTURE(serialize, v0_size64, 0, 64); | ||
BENCHMARK_CAPTURE(serialize, v0_size128, 0, 128); | ||
BENCHMARK_CAPTURE(serialize, v0_size256, 0, 256); | ||
BENCHMARK_CAPTURE(serialize, v0_size512, 0, 512); | ||
BENCHMARK_CAPTURE(serialize, v0_size1024, 0, 1024); | ||
|
||
BENCHMARK_CAPTURE(serialize, v1_size8, 1, 8); | ||
BENCHMARK_CAPTURE(serialize, v1_size16, 1, 16); | ||
BENCHMARK_CAPTURE(serialize, v1_size32, 1, 32); | ||
BENCHMARK_CAPTURE(serialize, v1_size64, 1, 64); | ||
BENCHMARK_CAPTURE(serialize, v1_size128, 1, 128); | ||
BENCHMARK_CAPTURE(serialize, v1_size256, 1, 256); | ||
BENCHMARK_CAPTURE(serialize, v1_size512, 1, 512); | ||
BENCHMARK_CAPTURE(serialize, v1_size1024, 1, 1024); | ||
|
||
BENCHMARK_CAPTURE(deserialize, v0_size8, 0, 8); | ||
BENCHMARK_CAPTURE(deserialize, v0_size16, 0, 16); | ||
BENCHMARK_CAPTURE(deserialize, v0_size32, 0, 32); | ||
BENCHMARK_CAPTURE(deserialize, v0_size64, 0, 64); | ||
BENCHMARK_CAPTURE(deserialize, v0_size128, 0, 128); | ||
BENCHMARK_CAPTURE(deserialize, v0_size256, 0, 256); | ||
BENCHMARK_CAPTURE(deserialize, v0_size512, 0, 512); | ||
BENCHMARK_CAPTURE(deserialize, v0_size1024, 0, 1024); | ||
|
||
BENCHMARK_CAPTURE(deserialize, v1_size8, 1, 8); | ||
BENCHMARK_CAPTURE(deserialize, v1_size16, 1, 16); | ||
BENCHMARK_CAPTURE(deserialize, v1_size32, 1, 32); | ||
BENCHMARK_CAPTURE(deserialize, v1_size64, 1, 64); | ||
BENCHMARK_CAPTURE(deserialize, v1_size128, 1, 128); | ||
BENCHMARK_CAPTURE(deserialize, v1_size256, 1, 256); | ||
BENCHMARK_CAPTURE(deserialize, v1_size512, 1, 512); | ||
BENCHMARK_CAPTURE(deserialize, v1_size1024, 1, 1024); | ||
|
||
} // namespace DB::bench |
Oops, something went wrong.