void test_writer_benchmark()

in cpp/bench_mark/bench_mark_src/bench_mark.cc [74:143]


void test_writer_benchmark(storage::TsFileWriter& writer, int loop_num,
                           std::vector<int> type_num) {
    std::cout << "start writing data" << std::endl;
    auto start = std::chrono::high_resolution_clock::now();
    int type = 0;
    for (int i = 0; i < loop_num; i++) {
        int ind = 0;
        for (auto num : type_num) {
            for (int j = 0; j < num; j++) {
                std::string device_name =
                    "root.db001.dev" + std::to_string(ind);
                std::string measurement_name = "m" + std::to_string(ind);
                long long currentTimeStamp = i;
                storage::TsRecord record(currentTimeStamp, device_name, 1);
                switch (type) {
                    case common::INT32: {
                        storage::DataPoint point(measurement_name, 10000 + i);
                        record.points_.push_back(point);
                        break;
                    }
                    case common::INT64: {
                        storage::DataPoint point(measurement_name,
                                                 int64_t(10000 + i));
                        record.points_.push_back(point);
                        break;
                    }
                    case common::BOOLEAN: {
                        storage::DataPoint point(measurement_name, i / 2 == 0);
                        record.points_.push_back(point);
                        break;
                    }
                    case common::FLOAT: {
                        storage::DataPoint point(measurement_name, (float)i);
                        record.points_.push_back(point);
                        break;
                    }
                    case common::DOUBLE: {
                        storage::DataPoint point(measurement_name, (double)i);
                        record.points_.push_back(point);
                        break;
                    }
                }
                int ret = writer.write_record(record);
                ASSERT(ret == 0);
                ind++;
            }
            type++;
        }
    }

    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = end - start;
    int timeseries_num = std::accumulate(type_num.begin(), type_num.end(), 0);
    std::cout << "writer loop: " << loop_num
              << " timeseries num: " << timeseries_num << " records in file"
              << "./test_data/tsfile_test.tsfile" << std::endl;
    std::cout << "total num of points: " << loop_num * timeseries_num
              << std::endl;
    std::cout << "writer data cost time: " << elapsed.count() << "s"
              << std::endl;
    std::cout << "writer data speed:"
              << loop_num * timeseries_num / elapsed.count() << " points/s"
              << std::endl;
    writer.flush();
    writer.close();
    auto end_flush = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed_flush = end_flush - end;
    std::cout << "flush data cost time: " << elapsed_flush.count() << "s"
              << std::endl;
}