Reset TimeRecord for sdk

Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
pull/4973/head^2
cai.zhang 2020-09-27 16:11:54 +08:00 committed by yefu.chen
parent 105b64decf
commit a87b1a42bc
8 changed files with 87 additions and 76 deletions

View File

@ -1,55 +0,0 @@
#include <Status.h>
#include <Field.h>
#include <MilvusApi.h>
#include <interface/ConnectionImpl.h>
#include "utils/Utils.h"
int main(int argc , char**argv) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
milvus::Status stat;
const std::string collectin_name = "collection0";
// Create
// milvus::FieldPtr field_ptr1 = std::make_shared<milvus::Field>();
// milvus::FieldPtr field_ptr2 = std::make_shared<milvus::Field>();
milvus::FieldPtr field_ptr3 = std::make_shared<milvus::Field>();
milvus::FieldPtr field_ptr4 = std::make_shared<milvus::Field>();
// field_ptr1->field_name = "field_1";
// field_ptr1->field_type = milvus::DataType::INT64;
//
// field_ptr2->field_name = "field_2";
// field_ptr2->field_type = milvus::DataType::FLOAT;
field_ptr3->field_name = "field_3";
field_ptr3->field_type = milvus::DataType::INT32;
field_ptr3->dim = 1;
field_ptr4->field_name = "field_vec";
field_ptr4->field_type = milvus::DataType::VECTOR_FLOAT;
field_ptr4->dim = 16;
// milvus::Mapping mapping = {collectin_name, {field_ptr1, field_ptr2, field_ptr3, field_ptr4}};
milvus::Mapping mapping = {collectin_name, {field_ptr3, field_ptr4}};
stat = client.CreateCollection(mapping, "test_extra_params");
// Get Collection info
milvus::Mapping map;
client.GetCollectionInfo(collectin_name, map);
for (auto &f : map.fields) {
std::cout << f->field_name << ":" << int(f->field_type) << ":" << f->dim << "DIM" << std::endl;
}
}

View File

@ -0,0 +1,48 @@
#include <Status.h>
#include <Field.h>
#include <MilvusApi.h>
#include <interface/ConnectionImpl.h>
#include "utils/Utils.h"
const int DIM = 128;
int main(int argc , char**argv) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
milvus::Status stat;
const std::string collectin_name = "collectionTest";
// Create
milvus::FieldPtr field_ptr1 = std::make_shared<milvus::Field>();
milvus::FieldPtr field_ptr2 = std::make_shared<milvus::Field>();
field_ptr1->field_name = "age";
field_ptr1->field_type = milvus::DataType::INT32;
field_ptr1->dim = 1;
field_ptr2->field_name = "field_vec";
field_ptr2->field_type = milvus::DataType::VECTOR_FLOAT;
field_ptr2->dim = DIM;
milvus::Mapping mapping = {collectin_name, {field_ptr1, field_ptr2}};
stat = client.CreateCollection(mapping, "extra_params");
// Get Collection info
milvus::Mapping map;
client.GetCollectionInfo(collectin_name, map);
for (auto &f : map.fields) {
std::cout << f->field_name << ":" << int(f->field_type) << ":" << f->dim << "DIM" << std::endl;
}
}

View File

@ -22,16 +22,17 @@
#include <random>
const int N = 200000;
const int DIM = 16;
const int LOOP = 1;
const int DIM = 128;
const milvus::FieldValue GetData() {
milvus::FieldValue value_map;
std::vector<int32_t> int32_data;
for (int i = 0; i < N; i++) {
int32_data.push_back(i);
}
std::default_random_engine eng(42);
std::normal_distribution<float> dis(0, 1);
std::vector<milvus::VectorData> vector_data;
@ -69,13 +70,10 @@ main(int argc, char* argv[]) {
ids_array.push_back(i);
}
milvus_sdk::TimeRecorder insert("insert");
for (int j = 0; j < LOOP; ++j) {
auto status = client.Insert("collection0", "tag01", data, ids_array);
if (!status.ok()){
return -1;
}
milvus_sdk::TimeRecorder insert("insert");
auto status = client.Insert("collection0", "tag01", data, ids_array);
if (!status.ok()){
return -1;
}
return 0;
}

View File

@ -20,6 +20,7 @@
#include <random>
const int TOP_K = 10;
const int LOOP = 1000;
int main(int argc , char**argv) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
@ -34,9 +35,9 @@ int main(int argc , char**argv) {
client.Connect(connect_param);
std::vector<int64_t> ids_array;
std::vector<std::string> partition_list;
partition_list.emplace_back("partition-1");
partition_list.emplace_back("partition-2");
partition_list.emplace_back("partition-3");
partition_list.emplace_back("default");
// partition_list.emplace_back("partition-2");
// partition_list.emplace_back("partition-3");
milvus::VectorParam vectorParam;
std::vector<milvus::VectorData> vector_records;
@ -65,10 +66,13 @@ int main(int argc , char**argv) {
vectorParam.vector_records = vector_records;
milvus::TopKQueryResult result;
milvus_sdk::TimeRecorder test_search("search");
auto status = client.Search("collection0", partition_list, "dsl", vectorParam, result);
for (int k = 0; k < LOOP; ++k) {
test_search.Start();
auto status = client.Search("collection0", partition_list, "dsl", vectorParam, result);
test_search.End();
}
test_search.Print(LOOP);
return 0;
return 0;
}

View File

@ -16,14 +16,26 @@
namespace milvus_sdk {
TimeRecorder::TimeRecorder(const std::string& title) : title_(title) {
start_ = std::chrono::system_clock::now();
std::cout << title_ << " begin..." << std::endl;
}
void TimeRecorder::Start() {
start_ = std::chrono::system_clock::now();
}
void TimeRecorder::End() {
end_ = std::chrono::system_clock::now();
int64_t span = (std::chrono::duration_cast<std::chrono::milliseconds>(end_ - start_)).count();
total_time_ = total_time_ + span;
}
void TimeRecorder::Print(int loop) {
uint64_t per_cost = total_time_ / loop;
std::cout << title_ << " totally cost: " << total_time_ << " ms" << std::endl;
std::cout << title_ << " per cost: " << per_cost << " ms" << std::endl;
}
TimeRecorder::~TimeRecorder() {
std::chrono::system_clock::time_point end = std::chrono::system_clock::now();
int64_t span = (std::chrono::duration_cast<std::chrono::milliseconds>(end - start_)).count();
std::cout << title_ << " totally cost: " << span << " ms" << std::endl;
}
} // namespace milvus_sdk

View File

@ -19,12 +19,16 @@ namespace milvus_sdk {
class TimeRecorder {
public:
explicit TimeRecorder(const std::string& title);
void Start();
void End();
void Print(int loop);
~TimeRecorder();
private:
std::string title_;
std::chrono::system_clock::time_point start_;
std::chrono::system_clock::time_point end_;
int64_t total_time_ = 0;
};
} // namespace milvus_sdk