summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands_bm.cpp
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-07-17 12:54:59 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2019-07-17 18:44:20 -0400
commitefeb79b3275f4ec6dc401a4c4a44fa4353d972ba (patch)
tree8d10de5406aa1efe0ad522816f3a38684c1e88cc /src/mongo/db/commands_bm.cpp
parent4a8d767411e17027204d5c4ae200fa525f13719d (diff)
downloadmongo-efeb79b3275f4ec6dc401a4c4a44fa4353d972ba.tar.gz
SERVER-42261 faster generic args predicates
Diffstat (limited to 'src/mongo/db/commands_bm.cpp')
-rw-r--r--src/mongo/db/commands_bm.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/mongo/db/commands_bm.cpp b/src/mongo/db/commands_bm.cpp
new file mode 100644
index 00000000000..82feaaf60f6
--- /dev/null
+++ b/src/mongo/db/commands_bm.cpp
@@ -0,0 +1,78 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * 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
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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 program with the OpenSSL library. You
+ * must comply with the Server Side 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>
+
+#include "mongo/base/string_data.h"
+#include "mongo/db/command_generic_argument.h"
+
+namespace mongo {
+namespace {
+
+static std::vector<std::string> keys{
+ "a", // short not found
+ "CrazyFieldDeliberatelyNotFound",
+ "$db",
+ "$audit",
+ "lsid",
+ "writeConcern",
+ "",
+};
+
+void BM_IsGeneric(benchmark::State& state) {
+ const auto& key = keys[state.range()];
+ state.SetLabel(key.c_str());
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(mongo::isGenericArgument(key));
+ }
+}
+void BM_IsRequestStripArgument(benchmark::State& state) {
+ const auto& key = keys[state.range()];
+ state.SetLabel(key.c_str());
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(mongo::isRequestStripArgument(key));
+ }
+}
+
+void BM_IsReplyStripArgument(benchmark::State& state) {
+ const auto& key = keys[state.range()];
+ state.SetLabel(key.c_str());
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(mongo::isReplyStripArgument(key));
+ }
+}
+
+BENCHMARK(BM_IsGeneric)->DenseRange(0, keys.size() - 1);
+BENCHMARK(BM_IsRequestStripArgument)->DenseRange(0, keys.size() - 1);
+BENCHMARK(BM_IsReplyStripArgument)->DenseRange(0, keys.size() - 1);
+
+} // namespace
+} // namespace mongo