Skip to content

Commit

Permalink
Merge bitcoin#13383: bench: Use non-throwing ParseDouble(...) instead…
Browse files Browse the repository at this point in the history
… of throwing boost::lexical_cast<double>(...)

f41d339 bench: Use non-throwing ParseDouble(...) instead of throwing boost::lexical_cast<double>(...) (practicalswift)

Pull request description:

  * Non-Boost is better than Boost.
  * Non-throwing is better than throwing.
  * Explicit error handling is better than implicit error handling.
  * `ParseDouble(…)` deserves to be used outside of its unit tests :-)

Tree-SHA512: a8cf04a5f8363cb7ced0bcaf1fed00e1e5dd6a63a6c11e5f0ba4e5c845b0df7c2b050d887075f158cd62dc7e02843ecaafc15e42e383c066461c6d7399e06b49
  • Loading branch information
laanwj committed Jun 4, 2018
2 parents f014933 + f41d339 commit 2722a1f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

#include <crypto/sha256.h>
#include <key.h>
#include <validation.h>
#include <util.h>
#include <random.h>

#include <boost/lexical_cast.hpp>
#include <util.h>
#include <utilstrencodings.h>
#include <validation.h>

#include <memory>

Expand Down Expand Up @@ -64,8 +63,11 @@ int main(int argc, char** argv)
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
bool is_list_only = gArgs.GetBoolArg("-list", false);

double scaling_factor = boost::lexical_cast<double>(scaling_str);

double scaling_factor;
if (!ParseDouble(scaling_str, &scaling_factor)) {
fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
return EXIT_FAILURE;
}

std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
Expand Down

0 comments on commit 2722a1f

Please sign in to comment.