diff --git a/faiss/perf_tests/bench_hnsw_add.cpp b/faiss/perf_tests/bench_hnsw_add.cpp new file mode 100644 index 0000000000..f975360803 --- /dev/null +++ b/faiss/perf_tests/bench_hnsw_add.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include "faiss/IndexHNSW.h" + +using namespace faiss; +DEFINE_uint32(d, 128, "dimension"); +DEFINE_uint32(n, 2000, "dimension"); +DEFINE_uint32(iterations, 20, "iterations"); +DEFINE_uint32(M, 32, "connections per vertex"); +DEFINE_uint32(num_omp_threads, 1, "number of omp threads"); + +DEFINE_uint32( + efConstruction, + 40, + "size of the dynamic list containing the nearest neighbors, which is used during index time"); + +static void bench_add( + benchmark::State& state, + int num_threads, + int d, + int n, + int M, + int efConstruction) { + std::vector x(d * n); + + float_rand(x.data(), d * n, 12345); + faiss::IndexHNSWFlat index(d, M); + index.hnsw.efConstruction = efConstruction; + + omp_set_num_threads(num_threads); + + for (auto _ : state) { + index.add(n, x.data()); + } +} + +int main(int argc, char** argv) { + benchmark::Initialize(&argc, argv); + gflags::AllowCommandLineReparsing(); + gflags::ParseCommandLineFlags(&argc, &argv, true); + + int iterations = FLAGS_iterations; + int d = FLAGS_d; + int n = FLAGS_n; + int M = FLAGS_M; + int efConstruction = FLAGS_efConstruction; + int num_threads = FLAGS_num_omp_threads; + benchmark::RegisterBenchmark( + fmt::format("hnsw_add_{}d_{}n_{}M", d, n, M).c_str(), + bench_add, + num_threads, + d, + n, + M, + efConstruction) + ->Iterations(iterations); + + benchmark::RunSpecifiedBenchmarks(); + benchmark::Shutdown(); +} diff --git a/faiss/perf_tests/bench_scalar_quantizer_accuracy.cpp b/faiss/perf_tests/bench_scalar_quantizer_accuracy.cpp index 7d8e70f958..4b7ef48a53 100644 --- a/faiss/perf_tests/bench_scalar_quantizer_accuracy.cpp +++ b/faiss/perf_tests/bench_scalar_quantizer_accuracy.cpp @@ -27,7 +27,6 @@ static void bench_reconstruction_error( ScalarQuantizer::QuantizerType type, int d, int n) { - state.SetLabel(faiss::get_compile_options()); std::vector x(d * n); float_rand(x.data(), d * n, 12345); @@ -64,7 +63,6 @@ static void bench_reconstruction_error( state.counters["ndiff_for_idempotence"] = ndiff; state.counters["code_size_two"] = codes.size(); - state.SetLabel(faiss::get_compile_options()); } int main(int argc, char** argv) { diff --git a/faiss/perf_tests/bench_scalar_quantizer_decode.cpp b/faiss/perf_tests/bench_scalar_quantizer_decode.cpp index 6cf3713a9b..c2fdbf4294 100644 --- a/faiss/perf_tests/bench_scalar_quantizer_decode.cpp +++ b/faiss/perf_tests/bench_scalar_quantizer_decode.cpp @@ -27,7 +27,6 @@ static void bench_decode( ScalarQuantizer::QuantizerType type, int d, int n) { - state.SetLabel(faiss::get_compile_options()); std::vector x(d * n); float_rand(x.data(), d * n, 12345); diff --git a/faiss/perf_tests/bench_scalar_quantizer_distance.cpp b/faiss/perf_tests/bench_scalar_quantizer_distance.cpp index b621ed39b3..81a92d7c7b 100644 --- a/faiss/perf_tests/bench_scalar_quantizer_distance.cpp +++ b/faiss/perf_tests/bench_scalar_quantizer_distance.cpp @@ -27,7 +27,6 @@ static void bench_distance( ScalarQuantizer::QuantizerType type, int n, int d) { - state.SetLabel(faiss::get_compile_options()); std::vector x(d * n); float_rand(x.data(), d * n, 12345); @@ -46,8 +45,6 @@ static void bench_distance( std::vector codes(code_size * n); sq.compute_codes(x.data(), codes.data(), n); - state.SetLabel(faiss::get_compile_options()); - std::unique_ptr dc( sq.get_distance_computer()); dc->codes = codes.data(); diff --git a/faiss/perf_tests/bench_scalar_quantizer_encode.cpp b/faiss/perf_tests/bench_scalar_quantizer_encode.cpp index 3f745ada9a..c35ecbd58c 100644 --- a/faiss/perf_tests/bench_scalar_quantizer_encode.cpp +++ b/faiss/perf_tests/bench_scalar_quantizer_encode.cpp @@ -28,7 +28,6 @@ static void bench_encode( ScalarQuantizer::QuantizerType type, int d, int n) { - state.SetLabel(faiss::get_compile_options()); std::vector x(d * n); float_rand(x.data(), d * n, 12345);