forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some benchmarks (vesoft-inc#493)
* Add some benchmarks * Update copyright * Address dutor's comments * Address dutor's and darion's comments
- Loading branch information
Showing
4 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
#include <folly/init/Init.h> | ||
#include <folly/Benchmark.h> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
|
||
BENCHMARK(Test1_RangeTestStr) { | ||
std::vector<int32_t> from; | ||
std::vector<std::string> to; | ||
BENCHMARK_SUSPEND { | ||
from.resize(1000, 0); | ||
to.resize(1000); | ||
} | ||
int32_t index = 0; | ||
for (auto& i : from) { | ||
to[index++] = std::to_string(i); | ||
} | ||
folly::doNotOptimizeAway(to); | ||
} | ||
BENCHMARK_RELATIVE(Test1_TransformStr) { | ||
std::vector<int32_t> from; | ||
std::vector<std::string> to; | ||
BENCHMARK_SUSPEND { | ||
from.resize(1000, 0); | ||
to.resize(1000); | ||
} | ||
std::transform(from.begin(), from.end(), to.begin(), [] (const auto& e) { | ||
return std::to_string(e); | ||
}); | ||
folly::doNotOptimizeAway(to); | ||
} | ||
|
||
BENCHMARK_DRAW_LINE(); | ||
|
||
BENCHMARK(Test2_RangeTestInt) { | ||
std::vector<int32_t> from; | ||
std::vector<int32_t> to; | ||
BENCHMARK_SUSPEND { | ||
from.resize(1000, 0); | ||
to.resize(1000); | ||
} | ||
int32_t index = 0; | ||
for (auto& i : from) { | ||
to[index++] = i; | ||
} | ||
folly::doNotOptimizeAway(to); | ||
} | ||
BENCHMARK_RELATIVE(Test2_TransformInt) { | ||
std::vector<int32_t> from; | ||
std::vector<int32_t> to; | ||
BENCHMARK_SUSPEND { | ||
from.resize(1000, 0); | ||
to.resize(1000); | ||
} | ||
std::transform(from.begin(), from.end(), to.begin(), [] (const auto& e) { | ||
return e; | ||
}); | ||
folly::doNotOptimizeAway(to); | ||
} | ||
|
||
BENCHMARK_DRAW_LINE(); | ||
|
||
BENCHMARK(Test3_RangeTestInt) { | ||
std::vector<int32_t> v; | ||
BENCHMARK_SUSPEND { | ||
v.resize(1000, 0); | ||
} | ||
for (auto& i : v) { | ||
(void)(i); | ||
int a; | ||
folly::doNotOptimizeAway(a); | ||
} | ||
} | ||
|
||
BENCHMARK_RELATIVE(Test3_ForEachInt) { | ||
std::vector<int32_t> v; | ||
BENCHMARK_SUSPEND { | ||
v.resize(1000, 0); | ||
} | ||
std::for_each(v.begin(), v.end(), [] (const auto&) { | ||
int a; | ||
folly::doNotOptimizeAway(a); | ||
}); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
folly::init(&argc, &argv, true); | ||
folly::runBenchmarks(); | ||
return 0; | ||
} | ||
|
||
|
||
/* | ||
Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz* | ||
-O2 | ||
============================================================================ | ||
RangeVsTransformBenchmark.cpprelative time/iter iters/s | ||
============================================================================ | ||
Test1_RangeTestStr 80.60us 12.41K | ||
Test1_TransformStr 100.47% 80.22us 12.47K | ||
---------------------------------------------------------------------------- | ||
Test2_RangeTestInt 713.67ns 1.40M | ||
Test2_TransformInt 99.99% 713.72ns 1.40M | ||
---------------------------------------------------------------------------- | ||
Test3_RangeTestInt 383.15ns 2.61M | ||
Test3_ForEachInt 100.63% 380.75ns 2.63M | ||
============================================================================ | ||
-O3 | ||
============================================================================ | ||
RangeVsTransformBenchmark.cpprelative time/iter iters/s | ||
============================================================================ | ||
Test1_RangeTestStr 84.19us 11.88K | ||
Test1_TransformStr 100.01% 84.18us 11.88K | ||
---------------------------------------------------------------------------- | ||
Test2_RangeTestInt 222.70ns 4.49M | ||
Test2_TransformInt 98.90% 225.18ns 4.44M | ||
---------------------------------------------------------------------------- | ||
Test3_RangeTestInt 395.93ns 2.53M | ||
Test3_ForEachInt 102.41% 386.61ns 2.59M | ||
============================================================================ | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "base/Base.h" | ||
#include <gtest/gtest.h> | ||
#include <rocksdb/db.h> | ||
#include <folly/Benchmark.h> | ||
#include "fs/TempDir.h" | ||
|
||
DEFINE_bool(do_compact, false, "Do compaction after puts"); | ||
DEFINE_int32(versions, 100, "Total versions"); | ||
|
||
namespace nebula { | ||
namespace kvstore { | ||
|
||
std::string genKey(int prefix, int version) { | ||
std::string key; | ||
key.reserve(8); | ||
key.append(reinterpret_cast<const char*>(&prefix), sizeof(prefix)); | ||
key.append(reinterpret_cast<const char*>(&version), sizeof(version)); | ||
return key; | ||
} | ||
|
||
void testFn(bool withVersion) { | ||
rocksdb::DB* db = nullptr; | ||
BENCHMARK_SUSPEND { | ||
fs::TempDir rootPath("/tmp/multi_versions_test.XXXXXX"); | ||
rocksdb::Options options; | ||
options.create_if_missing = true; | ||
options.disable_auto_compactions = true; | ||
auto status = rocksdb::DB::Open(options, rootPath.path(), &db); | ||
CHECK(status.ok()); | ||
rocksdb::WriteOptions woptions; | ||
for (int i = 0; i < 1000; i++) { | ||
for (int v = 0; v < FLAGS_versions; v++) { | ||
std::string key; | ||
if (withVersion) { | ||
key = genKey(i, v); | ||
} else { | ||
key = genKey(i, 0); | ||
} | ||
auto val = folly::stringPrintf("val_%d_%d", i, v); | ||
db->Put(woptions, | ||
rocksdb::Slice(key.data(), key.size()), | ||
rocksdb::Slice(val.data(), val.size())); | ||
} | ||
} | ||
if (FLAGS_do_compact) { | ||
rocksdb::CompactRangeOptions croptions; | ||
db->CompactRange(croptions, nullptr, nullptr); | ||
} | ||
} | ||
auto start = genKey(0, 0); | ||
rocksdb::ReadOptions roptions; | ||
rocksdb::Iterator* iter = db->NewIterator(roptions); | ||
if (iter) { | ||
iter->Seek(rocksdb::Slice(start)); | ||
} | ||
|
||
while (iter->Valid()) { | ||
iter->Next(); | ||
} | ||
BENCHMARK_SUSPEND { | ||
delete iter; | ||
db->Close(); | ||
delete db; | ||
} | ||
} | ||
|
||
BENCHMARK(WithVersionTest) { | ||
testFn(true); | ||
} | ||
|
||
BENCHMARK(WithOutVersionTest) { | ||
testFn(false); | ||
} | ||
|
||
} // namespace kvstore | ||
} // namespace nebula | ||
|
||
int main(int argc, char** argv) { | ||
folly::init(&argc, &argv, true); | ||
folly::runBenchmarks(); | ||
return 0; | ||
} | ||
|
||
/** | ||
Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz | ||
do_compact = false; | ||
============================================================================ | ||
MultiVersionBenchmark.cpprelative time/iter iters/s | ||
============================================================================ | ||
WithVersionTest 5.87ms 170.41 | ||
WithOutVersionTest 1.67ms 598.23 | ||
============================================================================ | ||
do_compact = true | ||
============================================================================ | ||
MultiVersionBenchmark.cpprelative time/iter iters/s | ||
============================================================================ | ||
WithVersionTest 25.44ms 39.30 | ||
WithOutVersionTest 329.21us 3.04K | ||
============================================================================ | ||
* | ||
* | ||
* */ |