-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Google Benchmark library and benchmark leveldb #1137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!
See below for an alternative arrangement that doesn't require checking in dead code.
|
||
- (void)testRunBenchmarks { | ||
// Enable to run benchmarks. | ||
if (false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably better captured as an early return so that this thing ends up written at a normal indent.
Also a better way to make this work is to create a new Benchmarks_iOS
target within the project and add this test to that target instead of Firestore_Tests
. That way we don't have to edit the files to run the benchmarks and they naturally exclude themselves during normal work.
Ok, I made a separate target and it runs the benchmarks. No more dead code. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM
@@ -709,6 +743,7 @@ | |||
6003F5B5195388D20070C39A /* Tests */, | |||
54764FAC1FAA0C390085E60A /* CoreTests */, | |||
54C9EDF22040E16300A969CD /* SwiftTests */, | |||
5CAE131A20FFFED600BE9A4A /* Firestore_Benchmarks_iOS */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could rename this in the left-hand nav to just "Benchmarks"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCTest.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be <XCTest/XCTest.h>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Firestore/Example/Podfile
Outdated
target 'Firestore_Benchmarks_iOS' do | ||
inherit! :search_paths | ||
|
||
pod 'GoogleBenchmark', :podspec => 'Tests/GoogleBenchmark/GoogleBenchmark.podspec' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this podspec just directly within Firestore/Example
(like ProtobufCpp and GoogleTest above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
'include/benchmark/*.h' | ||
] | ||
|
||
s.pod_target_xcconfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you add "${PODS_ROOT}/GoogleBenchmark/include"
to pod_user_config
you won't have to manually configure that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this as-is. The other setting did not work, and this currently matches GoogleTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some optional nitpicks (feel free to ignore), otherwise LGTM.
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCTest.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be just #import <XCTest/XCTest.h>;
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Firestore/Example/Podfile
Outdated
@@ -18,6 +18,11 @@ target 'Firestore_Example_iOS' do | |||
pod 'GoogleUtilities', :path => '../../' | |||
pod 'FirebaseFirestore', :path => '../../' | |||
|
|||
# pod 'leveldb-library' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this commented-out code be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
s.library = 'c++' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultranit: add a newline at the end of the file, so that Github doesn't display the annoying red symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
using firebase::firestore::model::DatabaseId; | ||
|
||
// Pre-existing document size | ||
static const int kDocumentSize = 1024 * 2; // 2 kb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: instead of using static
variables and functions, consider wrapping them in an anonymous namespace. It achieves the same thing, but is slightly less verbose, and has the advantage of working being more universal (static
cannot be applied to class
/struct
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
static NSString *LevelDBDir() { | ||
NSError *error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: move error
closer to the point of usage, in the if
statement scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
_emptyBuffer); | ||
} | ||
|
||
FSTLevelDB *_db; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the rules are for a pointer to an Objective-C object. A regular pointer would be uninitialized, so I'd suggest setting it to nullptr
. However, perhaps this pointer is set to nil
automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is automatically nil
: https://stackoverflow.com/a/9072040
// In each test, either overwrite index entries and documents, or just documents | ||
|
||
BENCHMARK_DEFINE_F(LevelDBFixture, RemoteEvent)(benchmark::State &state) { | ||
bool writeIndexes = (bool)state.range(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: use static_cast<bool>
instead of C-style conversion, it's easier to spot, greppable, and it's more clear what it does (C-style cast is much more powerful than a static_cast
, which may lead to surprising unintended conversions, especially when code is modified later on).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
BENCHMARK_DEFINE_F(LevelDBFixture, RemoteEvent)(benchmark::State &state) { | ||
bool writeIndexes = (bool)state.range(0); | ||
int64_t documentSize = state.range(1); | ||
int64_t docsToUpdate = state.range(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add #include <cstdint>;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bool writeIndexes = (bool)state.range(0); | ||
int64_t documentSize = state.range(1); | ||
int64_t docsToUpdate = state.range(2); | ||
std::string documentUpdate = UpdatedDocumentData((int)documentSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same optional nit about casting. Or perhaps just modify UpdatedDocumentData
to accept an int64_t
? There doesn't seem to be a need for divergence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
int64_t documentSize = state.range(1); | ||
int64_t docsToUpdate = state.range(2); | ||
std::string documentUpdate = UpdatedDocumentData((int)documentSize); | ||
for (auto _ : state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the loop variable a const reference? for (const auto& _ : state) {
. While _
variable is not used, copies are still being made. I don't know what state
contains, but presumably these are objects larger than a couple of int
s (otherwise, just leave as is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing the changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds benchmark capability. Includes a benchmark of leveldb writes with and without index writes. The test is currently disabled to avoid running by default.