diff --git a/cpp/test_client/main.cpp b/cpp/test_client/main.cpp index 0c2039f25c..52bc7e3c24 100644 --- a/cpp/test_client/main.cpp +++ b/cpp/test_client/main.cpp @@ -14,6 +14,7 @@ #include "src/FaissTest.h" #include "src/Log.h" +#include "src/ClientTest.h" #include "server/ServerConfig.h" INITIALIZE_EASYLOGGINGPP @@ -63,8 +64,13 @@ main(int argc, char *argv[]) { CLIENT_LOG_INFO << "Load config file:" << config_filename; +#if 1 ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); +#else + zilliz::vecwise::client::ClientTest::LoopTest(); + return 0; +#endif } void diff --git a/cpp/test_client/src/ClientTest.cpp b/cpp/test_client/src/ClientTest.cpp index 3078105466..163cd31972 100644 --- a/cpp/test_client/src/ClientTest.cpp +++ b/cpp/test_client/src/ClientTest.cpp @@ -3,6 +3,9 @@ // Unauthorized copying of this file, via any medium is strictly prohibited. // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// + +#include "ClientTest.h" + #include #include "utils/TimeRecorder.h" #include "utils/AttributeSerializer.h" @@ -14,6 +17,7 @@ using namespace zilliz; using namespace zilliz::vecwise; +using namespace zilliz::vecwise::client; namespace { static const int32_t VEC_DIMENSION = 256; @@ -62,6 +66,52 @@ namespace { static std::string s_id(CurrentTime()); return s_id; } + + void BuildVectors(int64_t from, int64_t to, + VecTensorList& tensor_list, + VecBinaryTensorList& bin_tensor_list) { + if(to <= from) { + return; + } + + int64_t count = to - from; + server::TimeRecorder rc(std::to_string(count) + " vectors built"); + for (int64_t k = from; k < count; k++) { + VecTensor tensor; + tensor.tensor.reserve(VEC_DIMENSION); + VecBinaryTensor bin_tensor; + bin_tensor.tensor.resize(VEC_DIMENSION * sizeof(double)); + double *d_p = (double *) (const_cast(bin_tensor.tensor.data())); + for (int32_t i = 0; i < VEC_DIMENSION; i++) { + double val = (double) (i + k); + tensor.tensor.push_back(val); + d_p[i] = val; + } + + server::AttribMap attrib_map; + attrib_map[TEST_ATTRIB_NUM] = "No." + std::to_string(k); + + tensor.uid = "normal_vec_" + std::to_string(k); + attrib_map[TEST_ATTRIB_COMMENT] = tensor.uid; + tensor.__set_attrib(attrib_map); + tensor_list.tensor_list.emplace_back(tensor); + + bin_tensor.uid = "binary_vec_" + std::to_string(k); + attrib_map[TEST_ATTRIB_COMMENT] = bin_tensor.uid; + bin_tensor.__set_attrib(attrib_map); + bin_tensor_list.tensor_list.emplace_back(bin_tensor); + + if ((k + 1) % 10000 == 0) { + CLIENT_LOG_INFO << k + 1 << " vectors built"; + } + } + + rc.Elapse("done"); + } +} + +void ClientTest::LoopTest() { + } TEST(AddVector, CLIENT_TEST) { @@ -83,40 +133,7 @@ TEST(AddVector, CLIENT_TEST) { const int64_t count = 100000; VecTensorList tensor_list; VecBinaryTensorList bin_tensor_list; - { - server::TimeRecorder rc(std::to_string(count) + " vectors built"); - for (int64_t k = 0; k < count; k++) { - VecTensor tensor; - tensor.tensor.reserve(VEC_DIMENSION); - VecBinaryTensor bin_tensor; - bin_tensor.tensor.resize(VEC_DIMENSION * sizeof(double)); - double *d_p = (double *) (const_cast(bin_tensor.tensor.data())); - for (int32_t i = 0; i < VEC_DIMENSION; i++) { - double val = (double) (i + k); - tensor.tensor.push_back(val); - d_p[i] = val; - } - - server::AttribMap attrib_map; - attrib_map[TEST_ATTRIB_NUM] = "No." + std::to_string(k); - - tensor.uid = "normal_vec_" + std::to_string(k); - attrib_map[TEST_ATTRIB_COMMENT] = tensor.uid; - tensor.__set_attrib(attrib_map); - tensor_list.tensor_list.emplace_back(tensor); - - bin_tensor.uid = "binary_vec_" + std::to_string(k); - attrib_map[TEST_ATTRIB_COMMENT] = bin_tensor.uid; - bin_tensor.__set_attrib(attrib_map); - bin_tensor_list.tensor_list.emplace_back(bin_tensor); - - if ((k + 1) % 10000 == 0) { - CLIENT_LOG_INFO << k + 1 << " vectors built"; - } - } - - rc.Elapse("done"); - } + BuildVectors(0, count, tensor_list, bin_tensor_list); // //add vectors one by one // { diff --git a/cpp/test_client/src/ClientTest.h b/cpp/test_client/src/ClientTest.h new file mode 100644 index 0000000000..e035ece2c3 --- /dev/null +++ b/cpp/test_client/src/ClientTest.h @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +namespace zilliz { +namespace vecwise { +namespace client { + +class ClientTest { +public: + static void LoopTest(); +}; + + +} +} +} diff --git a/cpp/test_client/src/FaissTest.cpp b/cpp/test_client/src/FaissTest.cpp index 62fbc7a2d0..a775c66099 100644 --- a/cpp/test_client/src/FaissTest.cpp +++ b/cpp/test_client/src/FaissTest.cpp @@ -1,7 +1,8 @@ -// -// Created by yhmo on 19-4-17. -// - +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ #include "FaissTest.h" #include "utils/TimeRecorder.h" @@ -16,6 +17,9 @@ #include +namespace zilliz { +namespace vecwise { +namespace client { namespace { void test_flat() { zilliz::vecwise::server::TimeRecorder recorder("test_flat"); @@ -27,14 +31,14 @@ namespace { float *xb = new float[d * nb]; float *xq = new float[d * nq]; - for(int i = 0; i < nb; i++) { - for(int j = 0; j < d; j++) + for (int i = 0; i < nb; i++) { + for (int j = 0; j < d; j++) xb[d * i + j] = drand48(); xb[d * i] += i / 1000.; } - for(int i = 0; i < nq; i++) { - for(int j = 0; j < d; j++) + for (int i = 0; i < nq; i++) { + for (int j = 0; j < d; j++) xq[d * i + j] = drand48(); xq[d * i] += i / 1000.; } @@ -61,21 +65,21 @@ namespace { // print results printf("I=\n"); - for(int i = 0; i < 5; i++) { - for(int j = 0; j < k; j++) + for (int i = 0; i < 5; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } printf("D=\n"); - for(int i = 0; i < 5; i++) { - for(int j = 0; j < k; j++) + for (int i = 0; i < 5; i++) { + for (int j = 0; j < k; j++) printf("%7g ", D[i * k + j]); printf("\n"); } - delete [] I; - delete [] D; + delete[] I; + delete[] D; } recorder.Record("search top 4"); @@ -88,27 +92,27 @@ namespace { // print results printf("I (5 first results)=\n"); - for(int i = 0; i < 5; i++) { - for(int j = 0; j < k; j++) + for (int i = 0; i < 5; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } printf("I (5 last results)=\n"); - for(int i = nq - 5; i < nq; i++) { - for(int j = 0; j < k; j++) + for (int i = nq - 5; i < nq; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } - delete [] I; - delete [] D; + delete[] I; + delete[] D; } recorder.Record("search xq"); - delete [] xb; - delete [] xq; + delete[] xb; + delete[] xq; recorder.Record("delete data"); } @@ -123,14 +127,14 @@ namespace { float *xb = new float[d * nb]; float *xq = new float[d * nq]; - for(int i = 0; i < nb; i++) { - for(int j = 0; j < d; j++) + for (int i = 0; i < nb; i++) { + for (int j = 0; j < d; j++) xb[d * i + j] = drand48(); xb[d * i] += i / 1000.; } - for(int i = 0; i < nq; i++) { - for(int j = 0; j < d; j++) + for (int i = 0; i < nq; i++) { + for (int j = 0; j < d; j++) xq[d * i + j] = drand48(); xq[d * i] += i / 1000.; } @@ -161,21 +165,21 @@ namespace { // print results printf("I (5 first results)=\n"); - for(int i = 0; i < 5; i++) { - for(int j = 0; j < k; j++) + for (int i = 0; i < 5; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } printf("I (5 last results)=\n"); - for(int i = nq - 5; i < nq; i++) { - for(int j = 0; j < k; j++) + for (int i = nq - 5; i < nq; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } - delete [] I; - delete [] D; + delete[] I; + delete[] D; } recorder.Record("search top 4"); @@ -209,27 +213,27 @@ namespace { // print results printf("I (5 first results)=\n"); - for(int i = 0; i < 5; i++) { - for(int j = 0; j < k; j++) + for (int i = 0; i < 5; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } printf("I (5 last results)=\n"); - for(int i = nq - 5; i < nq; i++) { - for(int j = 0; j < k; j++) + for (int i = nq - 5; i < nq; i++) { + for (int j = 0; j < k; j++) printf("%5ld ", I[i * k + j]); printf("\n"); } - delete [] I; - delete [] D; + delete[] I; + delete[] D; } recorder.Record("search xq"); - delete [] xb; - delete [] xq; + delete[] xb; + delete[] xq; recorder.Record("delete data"); } @@ -243,4 +247,8 @@ void FaissTest::test() { test_flat(); test_gpu(); +} + +} +} } \ No newline at end of file diff --git a/cpp/test_client/src/FaissTest.h b/cpp/test_client/src/FaissTest.h index eff81b5c1e..3a4e57f04f 100644 --- a/cpp/test_client/src/FaissTest.h +++ b/cpp/test_client/src/FaissTest.h @@ -1,15 +1,19 @@ -// -// Created by yhmo on 19-4-17. -// - -#ifndef VECWISE_ENGINE_FAISSTEST_H -#define VECWISE_ENGINE_FAISSTEST_H +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once +namespace zilliz { +namespace vecwise { +namespace client { class FaissTest { public: static void test(); }; - -#endif //VECWISE_ENGINE_FAISSTEST_H +} +} +}