Skip to content

Commit

Permalink
Refactor a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrusha97 committed Oct 20, 2017
1 parent 3c36f0e commit 7636ca6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 55 deletions.
84 changes: 45 additions & 39 deletions benchmarks/cpu_perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,50 @@ void measure_search_speed(const index_t &index, const dataset_t &control, size_t
}


void do_test(uint32_t seed, std::string input_file, boost::optional<size_t> control_size, size_t threads) {
random_t random(seed);
auto dataset = read_vectors(input_file);
normalize(dataset);
shuffle(dataset, random);

dataset_t control;
split_dataset(dataset, control, get_control_size(dataset, control_size));

LOG << "Building the index...";

index_t index;

for (const auto &x: dataset) {
index.insert(x.first, x.second);

if (index.index.nodes.size() % 10000 == 0) {
LOG << "Inserted " << index.index.nodes.size() << " vectors.";
}
}

LOG << "Done. Index contains " << index.index.nodes.size() << " elements.";

assess_index(index, dataset, control, threads);

LOG << "Measuring search performance...";
measure_search_speed(index, control, threads);

shuffle(dataset, random);

LOG << "Removing items. Index contains " << index.index.nodes.size() << " elements.";

for (const auto &x: dataset) {
index.remove(x.first);

if (index.index.nodes.size() % 10000 == 0) {
LOG << index.index.nodes.size() << " vectors are left.";
}
}

LOG << "Done.";
}


int main(int argc, const char *argv[]) {
namespace po = boost::program_options;

Expand Down Expand Up @@ -86,46 +130,8 @@ int main(int argc, const char *argv[]) {
return 1;
}

random_t random(seed);
auto dataset = read_vectors(input_file);
normalize(dataset);
shuffle(dataset, random);

dataset_t control;
split_dataset(dataset, control, get_control_size(dataset, control_size));

LOG << "Building the index...";

index_t index;

for (const auto &x: dataset) {
index.insert(x.first, x.second);

if (index.index.nodes.size() % 10000 == 0) {
LOG << "Inserted " << index.index.nodes.size() << " vectors.";
}
}

LOG << "Done. Index contains " << index.index.nodes.size() << " elements.";

assess_index(index, dataset, control, threads);

LOG << "Measuring search performance...";
measure_search_speed(index, control, threads);

shuffle(dataset, random);

LOG << "Removing items. Index contains " << index.index.nodes.size() << " elements.";

for (const auto &x: dataset) {
index.remove(x.first);

if (index.index.nodes.size() % 10000 == 0) {
LOG << index.index.nodes.size() << " vectors are left.";
}
}

LOG << "Done.";
do_test(seed, input_file, control_size, threads);

return 0;
}
38 changes: 22 additions & 16 deletions benchmarks/memory_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@
#include <boost/program_options.hpp>


void do_test(std::string input_file) {
vectors_reader_t reader(input_file);

LOG << "Building the index...";

index_t index;

std::pair<std::string, vector_t> item;
while (reader.read(item.first, item.second)) {
index.insert(item.first, item.second);

if (index.index.nodes.size() % 10000 == 0) {
LOG << "Inserted " << index.index.nodes.size() << " vectors.";
}
}

LOG << "Done. Index contains " << index.index.nodes.size() << " elements.";
LOG << "RSS: " << getCurrentRSS();
}


int main(int argc, const char *argv[]) {
namespace po = boost::program_options;

Expand Down Expand Up @@ -37,23 +58,8 @@ int main(int argc, const char *argv[]) {
return 1;
}

vectors_reader_t reader(input_file);

LOG << "Building the index...";

index_t index;

std::pair<std::string, vector_t> item;
while (reader.read(item.first, item.second)) {
index.insert(item.first, item.second);

if (index.index.nodes.size() % 10000 == 0) {
LOG << "Inserted " << index.index.nodes.size() << " vectors.";
}
}

LOG << "Done. Index contains " << index.index.nodes.size() << " elements.";
LOG << "RSS: " << getCurrentRSS();
do_test(input_file);

return 0;
}

0 comments on commit 7636ca6

Please sign in to comment.