diff options
author | Robert Guo <robertguo@me.com> | 2018-01-27 11:37:24 -0500 |
---|---|---|
committer | Robert Guo <robertguo@me.com> | 2018-01-27 11:39:46 -0500 |
commit | 8d9b68094ca79bce5da7cf530a2e14383b466a72 (patch) | |
tree | 32ae219957779a2baf60d26a42e7086e015f473a /src/mongo/unittest | |
parent | 0aeb5ce7e8d4a190dac43fd110533eef149f7880 (diff) | |
download | mongo-8d9b68094ca79bce5da7cf530a2e14383b466a72.tar.gz |
SERVER-32785 integrate Google Benchmark with SCons
Diffstat (limited to 'src/mongo/unittest')
-rw-r--r-- | src/mongo/unittest/SConscript | 7 | ||||
-rw-r--r-- | src/mongo/unittest/benchmark_test.cpp | 53 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript index 5dfd2e9f852..aeb99938cc5 100644 --- a/src/mongo/unittest/SConscript +++ b/src/mongo/unittest/SConscript @@ -38,6 +38,13 @@ env.CppUnitTest('unittest_test', 'unittest_test.cpp') env.CppUnitTest('fixture_test', 'fixture_test.cpp') env.CppUnitTest('temp_dir_test', 'temp_dir_test.cpp') +env.Benchmark( + target='benchmark_test', + source=[ + 'benchmark_test.cpp', + ], +) + env.Library( target='concurrency', source=[ diff --git a/src/mongo/unittest/benchmark_test.cpp b/src/mongo/unittest/benchmark_test.cpp new file mode 100644 index 00000000000..4949e5df668 --- /dev/null +++ b/src/mongo/unittest/benchmark_test.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2018 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the prograxm with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include <benchmark/benchmark.h> + +namespace { + +// This is a trivial test case to sanity check that "benchmark" runs. +// For more information on how benchmarks should be written, please refer to Google Benchmark's +// excellent README: https://github.com/google/benchmark/blob/v1.3.0/README.md +void BM_empty(benchmark::State& state) { + for (auto keepRunning : state) { + // The code inside this for-loop is what's being timed. + benchmark::DoNotOptimize(state.iterations()); + } +} + +// Register two benchmarks, one runs the "BM_empty" function in a single thread, the other runs a +// copy per CPU core. +BENCHMARK(BM_empty); +BENCHMARK(BM_empty)->ThreadPerCpu(); + +} // namespace + +// This function executes previously registered benchmarks. +BENCHMARK_MAIN(); |