Skip to content

Commit

Permalink
Isolate benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
micbou committed Jun 3, 2017
1 parent b141478 commit d266694
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cpp/ycm/CandidateRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ std::vector< const Candidate * > CandidateRepository::GetCandidatesForStrings(
}


void CandidateRepository::ClearCandidates() {
candidate_holder_.clear();
}


CandidateRepository::~CandidateRepository() {
for ( const CandidateHolder::value_type & pair : candidate_holder_ ) {
delete pair.second;
Expand Down
4 changes: 4 additions & 0 deletions cpp/ycm/CandidateRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class CandidateRepository {
YCM_DLL_EXPORT std::vector< const Candidate * > GetCandidatesForStrings(
const std::vector< std::string > &strings );

// This should only be used at the start of tests or benchmarks to isolate
// them.
YCM_DLL_EXPORT void ClearCandidates();

private:
CandidateRepository() {};
~CandidateRepository();
Expand Down
9 changes: 7 additions & 2 deletions cpp/ycm/benchmarks/IdentifierCompleter_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// along with ycmd. If not, see <http://www.gnu.org/licenses/>.

#include "benchmark/benchmark_api.h"
#include "CandidateRepository.h"
#include "IdentifierCompleter.h"
#include <iomanip>
#include <sstream>
Expand All @@ -25,6 +26,8 @@ namespace YouCompleteMe {
static void IdentifierCompleter_CandidatesWithCommonPrefix_bench(
benchmark::State& state ) {

CandidateRepository::Instance().ClearCandidates();

// Generate a list of candidates of the form a_a_a_[a-z]{5}.
std::vector< std::string > candidates;
for ( int i = 0; i < state.range( 0 ); i++ ) {
Expand All @@ -37,10 +40,12 @@ static void IdentifierCompleter_CandidatesWithCommonPrefix_bench(
candidates.push_back( candidate );
}

IdentifierCompleter completer( candidates );

while ( state.KeepRunning() )
IdentifierCompleter( candidates ).CandidatesForQuery( "aa" );
completer.CandidatesForQuery( "aa" );

state.SetComplexityN( state.range(0) );
state.SetComplexityN( state.range( 0 ) );
}

BENCHMARK( IdentifierCompleter_CandidatesWithCommonPrefix_bench )
Expand Down

0 comments on commit d266694

Please sign in to comment.