This is an automated email from the ASF dual-hosted git repository. colinlee pushed a commit to branch bench_mark in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit 84abd93af537a92134dabecee392f7a4037a4dad Author: ColinLee <[email protected]> AuthorDate: Wed Apr 9 19:45:59 2025 +0800 add write bench mark. --- cpp/bench_mark/CMakeLists.txt | 10 +- cpp/bench_mark/build.sh | 17 +-- cpp/bench_mark/src/bench_mark.cc | 25 ++++ cpp/bench_mark/src/bench_mark.h | 48 -------- cpp/bench_mark/src/bench_mark_c.cc | 203 ++++++++++++++++++++++++++++++++- cpp/bench_mark/src/bench_mark_c_cpp.h | 25 ++++ cpp/bench_mark/src/bench_mark_cpp.cc | 171 +++++++++++++-------------- cpp/bench_mark/src/bench_mark_utils.cc | 66 +++++++++++ cpp/bench_mark/src/bench_mark_utils.h | 32 ++++++ 9 files changed, 436 insertions(+), 161 deletions(-) diff --git a/cpp/bench_mark/CMakeLists.txt b/cpp/bench_mark/CMakeLists.txt index ddb1b333..36f8dac9 100644 --- a/cpp/bench_mark/CMakeLists.txt +++ b/cpp/bench_mark/CMakeLists.txt @@ -17,7 +17,7 @@ specific language governing permissions and limitations under the License. ]] message("Running in bench_mark directory") -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.11) project(tsfile_bench_mark_project) if(DEFINED ENV{CXX}) @@ -32,6 +32,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/third_party/zlib-1.2.13 ${CMAKE_SOURCE_DIR}/third_party/google_snappy ${CMAKE_SOURCE_DIR}/third_party/antlr4-cpp-runtime-4/runtime/src + ${CMAKE_SOURCE_DIR}/src + ) link_directories(${LIBRARY_OUTPUT_PATH}) @@ -43,5 +45,9 @@ else() endif() message("CMAKE DEBUG: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}") -add_executable(bench_mark src/bench_mark_cpp.cc src/bench_mark_c.cc) +add_executable(bench_mark + src/bench_mark_cpp.cc + src/bench_mark_c.cc + src/bench_mark.cc + src/bench_mark_utils.cc) target_link_libraries(bench_mark tsfile) diff --git a/cpp/bench_mark/build.sh b/cpp/bench_mark/build.sh index c8c534f7..2f40dee3 100644 --- a/cpp/bench_mark/build.sh +++ b/cpp/bench_mark/build.sh @@ -20,19 +20,8 @@ build_type=Debug use_cpp11=1 -if [ ${build_type} = "Debug" ] -then - mkdir -p build/Debug - cd build/Debug - use_sdk_debug=1 -else - mkdir -p build/Release - cd build/Release - use_sdk_debug=0 -fi +mkdir -p build/Release +cd build/Release -echo "use_sdk_debug=${use_sdk_debug}" -cmake ../../ \ - -DUSE_SDK_DEBUG=$use_sdk_debug \ - -DUSE_CPP11=$use_cpp11 +cmake ../../ make diff --git a/cpp/bench_mark/src/bench_mark.cc b/cpp/bench_mark/src/bench_mark.cc new file mode 100644 index 00000000..be38d5bb --- /dev/null +++ b/cpp/bench_mark/src/bench_mark.cc @@ -0,0 +1,25 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 "bench_mark_c_cpp.h" + +int main() { + bench_mark_cpp_write(); + bench_mark_c_write(); +} diff --git a/cpp/bench_mark/src/bench_mark.h b/cpp/bench_mark/src/bench_mark.h deleted file mode 100644 index 6fcb64ea..00000000 --- a/cpp/bench_mark/src/bench_mark.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Created by colin on 4/2/25. -// - -#ifndef TSFILE_BENCH_MARK_BENCH_MARK_H -#define TSFILE_BENCH_MARK_BENCH_MARK_H -#include <iostream> -#include "bench_conf.h" -namespace bench { - -static const char* data_types_name[5] = { - "BOOLEAN", "INT32", "INT64", "FLOAT", "DOUBLE" -}; - -static const int data_type[5] = { - 0, 1, 2, 3, 4 -}; - -static int column_num = 0; - -inline void print_config () { - std::cout << "TsFile CPP benchmark" << std::endl; - std::cout << "Schema Configuration:" << std::endl; - std::cout << "Tag Column num: " << bench::tag_num << std::endl; - std::cout << "Diversity rate of tag :" << std::endl; - std::cout << bench::diversity_rate[0]; - for (int i = 1; i < bench::tag_num; i++) { - std::cout << ":"<< bench::diversity_rate[i]; - } - - std::cout<<std::endl; - std::cout << "Filed Column and types: " << std::endl; - column_num = 0; - column_num += diversity_rate.size(); - for (int i = 0; i < 5; i++) { - std::cout << bench::data_types_name[i] << "x" << bench::field_type_vector[i] << " "; - column_num += field_type_vector[i]; - } - std::cout << std::endl; - std::cout << "Tablet num:" << bench::tablet_num << std::endl; - std::cout << "Tablet row num:" << bench::tablet_row_num << std::endl; - std::cout << "Total points is " << tablet_num * tablet_row_num * column_num<< std::endl; -} - -} - - -#endif // TSFILE_BENCH_MARK_BENCH_MARK_H diff --git a/cpp/bench_mark/src/bench_mark_c.cc b/cpp/bench_mark/src/bench_mark_c.cc index b9988fb0..a2da409f 100644 --- a/cpp/bench_mark/src/bench_mark_c.cc +++ b/cpp/bench_mark/src/bench_mark_c.cc @@ -1,5 +1,200 @@ -// -// Created by colin on 4/2/25. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 "bench_mark.h" +#include <chrono> +#include <iostream> +#include <string> + +#include "bench_conf.h" +#include "bench_mark_c_cpp.h" +#include "bench_mark_utils.h" +#include "cwrapper/tsfile_cwrapper.h" +#define HANDLE_ERROR(err_no) \ + do { \ + if (err_no != 0) { \ + printf("get err no: %d", err_no); \ + return err_no; \ + } \ + } while (0) + +char** column_list; +TSDataType* data_types_c; + +int bench_mark_c_write() { + ERRNO code = 0; + char* table_name = "TestTable"; + print_config(); + TableSchema table_schema; + + table_schema.table_name = strdup(table_name); + int column = 0; + for (auto data_type : bench::field_type_vector) { + column += data_type; + } + column_list = new char*[column + 2]; + data_types_c = new TSDataType[column + 2]; + + table_schema.column_schemas = + (ColumnSchema*)malloc(sizeof(ColumnSchema) * column); + table_schema.column_num = column + 2; + table_schema.column_schemas[0] = + (ColumnSchema){.column_name = strdup("TAG1"), + .data_type = TS_DATATYPE_STRING, + .column_category = TAG}; + column_list[0] = strdup("TAG1"); + data_types_c[0] = TS_DATATYPE_STRING; + table_schema.column_schemas[1] = + (ColumnSchema){.column_name = strdup("TAG2"), + .data_type = TS_DATATYPE_STRING, + .column_category = TAG}; + column_list[1] = strdup("TAG2"); + data_types_c[1] = TS_DATATYPE_STRING; + + int col = 2; + for (int i = 0; i < bench::field_type_vector.size();i++) { + int column_num = bench::field_type_vector[i]; + for (int j = 0; j < column_num; j++) { + column_list[col] = + strdup(std::string("FIELD" + std::to_string(i)).c_str()); + data_types_c[col] = static_cast<TSDataType>(data_type[i]); + table_schema.column_schemas[col++] = (ColumnSchema){ + .column_name = + strdup(std::string("FIELD" + std::to_string(i)).c_str()), + .data_type = static_cast<TSDataType>(data_type[i]), + .column_category = FIELD}; + } + } + + remove("bench_mark_c.tsfile"); + WriteFile file = write_file_new("bench_mark_c.tsfile", &code); + HANDLE_ERROR(code); + TsFileWriter writer = tsfile_writer_new(file, &table_schema, &code); + HANDLE_ERROR(code); + int64_t prepare_time = 0; + int64_t writing_time = 0; + int64_t timestamp = 0; + int64_t row_num = + bench::tag1_num * bench::tag2_num * bench::timestamp_per_tag; + auto start = std::chrono::high_resolution_clock::now(); + + for (int i = 0; i < bench::tablet_num; i++) { + print_progress_bar(i, bench::tablet_num); + auto prepare_start = std::chrono::high_resolution_clock::now(); + auto tablet = + tablet_new(column_list, data_types_c, column + 2, row_num); + for (int tag1 = 0; tag1 < bench::tag1_num; tag1++) { + for (int tag2 = 0; tag2 < bench::tag2_num; tag2++) { + for (int row = 0; row < bench::timestamp_per_tag; row++) { + tablet_add_timestamp(tablet, row, timestamp + row); + tablet_add_value_by_index_string( + tablet, row, 0, + std::string("TAG1_" + std::to_string(tag1)).c_str()); + tablet_add_value_by_index_string( + tablet, row, 1, + std::string("TAG2_" + std::to_string(tag2)).c_str()); + for (int col = 2; col < column + 2; col++) { + switch (data_types_c[col]) { + case TS_DATATYPE_INT32: + tablet_add_value_by_index_int32_t( + tablet, row, col, + static_cast<int32_t>(timestamp)); + break; + case TS_DATATYPE_INT64: + tablet_add_value_by_index_int64_t( + tablet, row, col, + static_cast<int64_t>(timestamp)); + break; + case TS_DATATYPE_FLOAT: + tablet_add_value_by_index_float( + tablet, row, col, + static_cast<float>(timestamp)); + break; + case TS_DATATYPE_DOUBLE: + tablet_add_value_by_index_double( + tablet, row, col, + static_cast<double>(timestamp)); + break; + case TS_DATATYPE_BOOLEAN: + tablet_add_value_by_index_bool( + tablet, row, col, + static_cast<bool>(timestamp % 2)); + break; + default: + // + } + } + } + } + } + auto prepare_end = std::chrono::high_resolution_clock::now(); + prepare_time += std::chrono::duration_cast<std::chrono::microseconds>( + prepare_end - prepare_start) + .count(); + + auto writing_start = std::chrono::high_resolution_clock::now(); + tsfile_writer_write(writer, tablet); + auto writing_end = std::chrono::high_resolution_clock::now(); + writing_time += std::chrono::duration_cast<std::chrono::microseconds>( + writing_end - writing_start) + .count(); + free_tablet(&tablet); + timestamp += bench::timestamp_per_tag; + } + + auto close_start = std::chrono::high_resolution_clock::now(); + tsfile_writer_close(writer); + auto close_end = std::chrono::high_resolution_clock::now(); + + writing_time += std::chrono::duration_cast<std::chrono::microseconds>( + close_end - close_start) + .count(); + free_write_file(&file); + auto end = std::chrono::high_resolution_clock::now(); + + FILE* file_to_size = fopen("bench_mark_c.tsfile", "rb"); + if (!file_to_size) { + std::cout << "unable to open file" << std::endl; + return -1; + } + fseeko(file_to_size, 0, SEEK_END); + off_t size = ftello(file_to_size); + fclose(file_to_size); + + std::cout << "finish bench mark for c" << std::endl; + std::cout << "tsfile size is " << size << " bytes " << " ~ " << size / 1024 + << "KB" << std::endl; + + double pre_time = prepare_time / 1000.0 / 1000.0; + double write_time = writing_time / 1000.0 / 1000.0; + std::cout << "prepare data time is " << pre_time << " s" << std::endl; + std::cout << "writing data time is " << write_time << " s" << std::endl; + std::cout << "writing speed is " + << static_cast<long long>(bench::tablet_num * bench::tag1_num * + bench::tag2_num * + bench::timestamp_per_tag * + (column + 2) / (pre_time + write_time)) + << " points/s" << std::endl; + std::cout << "total time is " + << std::chrono::duration_cast<std::chrono::microseconds>(end - + start) + .count() / + 1000.0 / 1000.0 + << " s" << std::endl; + return 0; +} \ No newline at end of file diff --git a/cpp/bench_mark/src/bench_mark_c_cpp.h b/cpp/bench_mark/src/bench_mark_c_cpp.h new file mode 100644 index 00000000..9f5cb4ac --- /dev/null +++ b/cpp/bench_mark/src/bench_mark_c_cpp.h @@ -0,0 +1,25 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +#ifndef TSFILE_BENCH_MARK_BENCH_MARK_C_CPP_H +#define TSFILE_BENCH_MARK_BENCH_MARK_C_CPP_H + +int bench_mark_c_write(); +int bench_mark_cpp_write(); + +#endif // TSFILE_BENCH_MARK_BENCH_MARK_C_CPP_H \ No newline at end of file diff --git a/cpp/bench_mark/src/bench_mark_cpp.cc b/cpp/bench_mark/src/bench_mark_cpp.cc index 819d40ac..56d886fa 100644 --- a/cpp/bench_mark/src/bench_mark_cpp.cc +++ b/cpp/bench_mark/src/bench_mark_cpp.cc @@ -16,17 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -#include <sys/types.h> + +#include "bench_mark_c_cpp.h" #include <chrono> -#include <cmath> #include <iostream> -#include <numeric> #include <string> #include <vector> #include "bench_conf.h" -#include "bench_mark.h" +#include "bench_mark_utils.h" #include "common/db_common.h" #include "common/path.h" #include "common/tablet.h" @@ -40,23 +39,6 @@ using namespace common; std::vector<std::string> columns_name; std::vector<TSDataType> data_types; -void printProgressBar(int current, int total, int barWidth = 50) { - float progress = static_cast<float>(current) / total; - int pos = barWidth * progress; - - std::cout << "["; - for (int i = 0; i < barWidth; ++i) { - if (i < pos) - std::cout << "="; - else if (i == pos) - std::cout << ">"; - else - std::cout << " "; - } - std::cout << "] " << int(progress * 100.0) << " %\r"; - std::cout.flush(); -} - TableSchema* gen_table_schema(const std::vector<int>& field_type_vector) { std::vector<common::ColumnSchema> schemas; // 2 TAG Columns default @@ -70,23 +52,25 @@ TableSchema* gen_table_schema(const std::vector<int>& field_type_vector) { for (int i = 0; i < field_type_vector.size(); i++) { int column_num = field_type_vector[i]; for (int j = 0; j < column_num; j++) { - std::string column_name = + auto column_name = std::string("FIELD" + std::to_string(i) + std::to_string(j)); - TSDataType data_type = static_cast<TSDataType>(bench::data_type[i]); - data_types.push_back(data_type); + auto type = static_cast<TSDataType>(data_type[i]); + data_types.push_back(type); columns_name.push_back(column_name); - schemas.emplace_back(column_name, data_type, ColumnCategory::FIELD); + schemas.emplace_back(column_name, type, ColumnCategory::FIELD); } } return new TableSchema("TestTable", schemas); } -int main() { +int bench_mark_cpp_write() { int code = common::E_OK; - bench::print_config(); + print_config(); + remove("bench_mark_cpp.tsfile"); common::init_config_value(); // benchmark for write - storage::WriteFile file = storage::WriteFile(); + WriteFile file = WriteFile(); + int flags = O_WRONLY | O_CREAT | O_TRUNC; #ifdef _WIN32 flags |= O_BINARY; @@ -97,85 +81,79 @@ int main() { return -1; } - TableSchema* table_schema = - gen_table_schema(bench::field_type_vector); + TableSchema* table_schema = gen_table_schema(bench::field_type_vector); auto writer = new TsFileTableWriter(&file, table_schema); delete (table_schema); + int64_t timestamp = 0; - auto start = std::chrono::high_resolution_clock::now(); int64_t prepare_time = 0; int64_t writing_time = 0; - int batch_num = bench::tablet_row_num * bench::diversity_rate[0]; - int batch_num2 = batch_num * bench::diversity_rate[1]; - for (int i = 0; i < bench::tablet_num; i++) { - printProgressBar(i, bench::tablet_num); - auto tablet_start = std::chrono::high_resolution_clock::now(); - auto* tablet = - new Tablet(columns_name, data_types, bench::tablet_row_num); - int tag1_num = 0; - int tag2_num = 0; - int tag1_row_num = 0; - int tag2_row_num = 0; - for (int j = 0; j < bench::tablet_row_num; j++) { - if (tag1_row_num > batch_num) { - tag1_row_num = 0; - tag1_num++; - tag2_row_num = 0; - tag2_num = 0; - } - tablet->add_timestamp(j, timestamp++); - tablet->add_value( - j, 0, std::string("tag1_" + std::to_string(tag1_num)).c_str()); - tag1_row_num++; - if (tag2_row_num > batch_num2) { - tag2_row_num = 0; - tag2_num++; - } - tablet->add_value( - j, 1, std::string("tag2_" + std::to_string(tag2_num)).c_str()); - tag2_row_num++; - for (int col = 2; col < data_types.size(); col++) { - switch (data_types[col]) { - case TSDataType::INT64: - tablet->add_value(j, col, - static_cast<int64_t>(timestamp)); - break; - case TSDataType::FLOAT: - tablet->add_value(j, col, - static_cast<float>(timestamp * 1.1)); - break; - case TSDataType::DOUBLE: - tablet->add_value(j, col, - static_cast<double>(timestamp * 1.1)); - break; - case TSDataType::INT32: - tablet->add_value(j, col, - static_cast<int32_t>(timestamp)); - break; - case TSDataType::BOOLEAN: - tablet->add_value(j, col, - static_cast<bool>(timestamp % 2)); - break; - default: - // + + auto start = std::chrono::high_resolution_clock::now(); + + for (int tablet_i = 0; tablet_i < bench::tablet_num; tablet_i++) { + print_progress_bar(tablet_i, bench::tablet_num); + auto prepare_start = std::chrono::high_resolution_clock::now(); + auto tablet = Tablet( + columns_name, data_types, + bench::tag1_num * bench::tag2_num * bench::timestamp_per_tag); + for (int tag1 = 0; tag1 < bench::tag1_num; tag1++) { + for (int tag2 = 0; tag2 < bench::tag2_num; tag2++) { + for (int row = 0; row < bench::timestamp_per_tag; row++) { + tablet.add_timestamp(row, timestamp + row); + tablet.add_value(row, 0, std::string("tag1_" + std::to_string(tag1)).c_str()); + tablet.add_value(row, 1, std::string("tag2_" + std::to_string(tag2)).c_str()); + for (int col = 0; col < data_types.size(); col++) { + switch (data_types[col]) { + case TSDataType::INT32: + tablet.add_value( + row, col, static_cast<int32_t>(timestamp)); + break; + case TSDataType::INT64: + tablet.add_value( + row, col, static_cast<int64_t>(timestamp)); + break; + case TSDataType::FLOAT: + tablet.add_value( + row, col, + static_cast<float>(timestamp * 1.1)); + break; + case TSDataType::DOUBLE: + tablet.add_value( + row, col, + static_cast<double>(timestamp * 1.1)); + break; + + case TSDataType::BOOLEAN: + tablet.add_value( + row, col, static_cast<bool>(timestamp % 2)); + break; + default: + // + } + } } } } - auto tablet_end = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast<std::chrono::microseconds>( - tablet_end - tablet_start); - prepare_time += duration.count(); + auto prepare_end = std::chrono::high_resolution_clock::now(); + + prepare_time += std::chrono::duration_cast<std::chrono::microseconds>( + prepare_end - prepare_start) + .count(); + auto write_start = std::chrono::high_resolution_clock::now(); - writer->write_table(*tablet); + writer->write_table(tablet); auto write_end = std::chrono::high_resolution_clock::now(); writing_time += std::chrono::duration_cast<std::chrono::microseconds>( write_end - write_start) .count(); - delete tablet; + timestamp += bench::timestamp_per_tag; } + auto close_start = std::chrono::high_resolution_clock::now(); writer->close(); auto close_end = std::chrono::high_resolution_clock::now(); + writing_time += std::chrono::duration_cast<std::chrono::microseconds>( close_end - close_start) .count(); @@ -190,15 +168,20 @@ int main() { fseeko(file_to_size, 0, SEEK_END); off_t size = ftello(file_to_size); fclose(file_to_size); + + std::cout << "====================" << std::endl; std::cout << "finish bench mark for cpp" << std::endl; std::cout << "tsfile size is " << size << " bytes " << " ~ " << size / 1024 << "KB" << std::endl; - float pre_time = prepare_time / 1000.0 / 1000.0; - float write_time = writing_time / 1000.0 / 1000.0; + + double pre_time = prepare_time / 1000.0 / 1000.0; + double write_time = writing_time / 1000.0 / 1000.0; std::cout << "prepare data time is " << pre_time << " s" << std::endl; std::cout << "writing data time is " << write_time << " s" << std::endl; std::cout << "writing speed is " - << static_cast<long long>(bench::tablet_num * bench::tablet_row_num * bench::column_num / + << static_cast<long long>( + bench::tablet_num * bench::tag1_num * bench::tag2_num * + bench::timestamp_per_tag * data_types.size() / (pre_time + write_time)) << " points/s" << std::endl; std::cout << "total time is " @@ -207,4 +190,6 @@ int main() { .count() / 1000.0 / 1000.0 << " s" << std::endl; + std::cout << "====================" << std::endl; + return 0; } diff --git a/cpp/bench_mark/src/bench_mark_utils.cc b/cpp/bench_mark/src/bench_mark_utils.cc new file mode 100644 index 00000000..842aa88e --- /dev/null +++ b/cpp/bench_mark/src/bench_mark_utils.cc @@ -0,0 +1,66 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 "bench_mark_utils.h" + +#include <iostream> + +#include "bench_conf.h" +using namespace bench; + +void print_config() { + std::cout << "TsFile benchmark" << std::endl; + std::cout << "Schema Configuration:" << std::endl; + std::cout << "Tag Column num: " << 2 << std::endl; + std::cout << "TAG1 num: " << tag1_num << " TAG2 num: " << tag2_num + << std::endl; + + std::cout << std::endl; + std::cout << "Filed Column and types: " << std::endl; + int column_num = 0; + for (int i = 0; i < 5; i++) { + std::cout << data_types_name[i] << "x" << field_type_vector[i] << " "; + column_num += field_type_vector[i]; + } + std::cout << std::endl; + std::cout << "Tablet num:" << tablet_num << std::endl; + std::cout << "Tablet row num per tag:" << timestamp_per_tag << std::endl; + std::cout << "Total points is " + << tablet_num * tag1_num * tag2_num * timestamp_per_tag * + (column_num + 2) + << std::endl; + std::cout << "====================" << std::endl; +} + +void print_progress_bar(int current, int total, int barWidth) { + float progress = static_cast<float>(current) / total; + int pos = barWidth * progress; + + std::cout << "["; + for (int i = 0; i < barWidth; ++i) { + if (i < pos) + std::cout << "="; + else if (i == pos) + std::cout << ">"; + else + std::cout << " "; + } + std::cout << "] " << int(progress * 100.0) << " %\r"; + std::cout.flush(); +} diff --git a/cpp/bench_mark/src/bench_mark_utils.h b/cpp/bench_mark/src/bench_mark_utils.h new file mode 100644 index 00000000..a46a67ff --- /dev/null +++ b/cpp/bench_mark/src/bench_mark_utils.h @@ -0,0 +1,32 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +#ifndef TSFILE_BENCH_MARK_BENCH_MARK_UTILS_H +#define TSFILE_BENCH_MARK_BENCH_MARK_UTILS_H + + +static const char* data_types_name[5] = {"BOOLEAN", "INT32", "INT64", "FLOAT", + "DOUBLE"}; +static const int data_type[5] = {0, 1, 2, 3, 4}; + +void print_config(); +void print_progress_bar(int current, int total, int barWidth = 50); + + +#endif // TSFILE_BENCH_MARK_BENCH_MARK_UTILS_H \ No newline at end of file
