From c302acb1590211929c706323cb8021fea5466e4f Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Wed, 11 Jan 2017 20:48:04 +0530 Subject: [PATCH] Added a basic benchmark. --- CMakeLists.txt | 2 ++ src/main/benchmark.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/benchmark.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 88d2fbb4..c6990dd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,10 @@ link_directories(${CMAKE_SOURCE_DIR}/external/${ROCKSDB_NAME}) add_executable(typesense_test test/forarray_test.cpp test/art_test.cpp test/collection_test.cpp test/topster_test.cpp ${SRC_FILES}) add_executable(search ${HEADER_FILES} ${SRC_FILES} src/main/main.cpp) +add_executable(benchmark ${HEADER_FILES} ${SRC_FILES} src/main/benchmark.cpp) add_executable(typesense-server ${HEADER_FILES} ${SRC_FILES} src/main/server.cpp) target_link_libraries(typesense_test for rocksdb gtest gtest_main) target_link_libraries(search for pthread rocksdb) +target_link_libraries(benchmark for pthread rocksdb) target_link_libraries(typesense-server for curl h2o-evloop pthread rocksdb ssl crypto) \ No newline at end of file diff --git a/src/main/benchmark.cpp b/src/main/benchmark.cpp new file mode 100644 index 00000000..87f9d4c4 --- /dev/null +++ b/src/main/benchmark.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "string_utils.h" +#include "collection.h" +#include "collection_manager.h" + +using namespace std; + +int main() { + system("rm -rf /tmp/typesense-data && mkdir -p /tmp/typesense-data"); + + std::vector fields_to_index = {field("title", field_types::STRING)}; + std::vector rank_fields = {"points"}; + Store *store = new Store("/tmp/typesense-data"); + CollectionManager & collectionManager = CollectionManager::get_instance(); + collectionManager.init(store); + + Collection *collection = collectionManager.get_collection("collection"); + if(collection == nullptr) { + collection = collectionManager.create_collection("collection", fields_to_index, rank_fields); + } + + std::ifstream infile("/Users/kishore/Downloads/hnstories.jsonl"); + + std::string json_line; + + while (std::getline(infile, json_line)) { + collection->add(json_line); + } + + infile.close(); + cout << "FINISHED INDEXING!" << endl << flush; + + std::vector search_fields = {"title"}; + + std::vector queries = {"the", "and", "to", "of", "in"}; + auto counter = 0; + uint64_t results_total = 0; // to prevent optimizations! + + auto begin = std::chrono::high_resolution_clock::now(); + + while(counter < 3000) { + auto i = counter % 5; + auto results = collection->search(queries[i], search_fields, 1, 100); + results_total += results.size(); + counter++; + } + + long long int timeMillis = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - begin).count(); + cout << "Time taken: " << timeMillis << "ms" << endl; + cout << "Total: " << results_total << endl; + return 0; +} \ No newline at end of file