forked from BoostGSoC19/Real
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds benchmarks and fixes link issues
- Loading branch information
1 parent
002a0e0
commit e2a3632
Showing
12 changed files
with
252 additions
and
115 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
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 |
---|---|---|
@@ -1,17 +1,33 @@ | ||
#include <iostream> | ||
#ifndef BOOST_REAL_BENCHMARK_HELPERS_HPP | ||
#define BOOST_REAL_BENCHMARK_HELPERS_HPP | ||
|
||
#include <real/real.hpp> | ||
|
||
class NullBuffer : public std::streambuf | ||
{ | ||
public: | ||
int overflow(int c) { return c; } | ||
}; | ||
constexpr void realOperationEq(boost::real::real& lhs, boost::real::real& rhs, | ||
boost::real::OPERATION op) { | ||
switch (op) { | ||
case boost::real::OPERATION::ADDITION: | ||
lhs += rhs; | ||
break; | ||
case boost::real::OPERATION::SUBTRACTION: | ||
lhs -= rhs; | ||
break; | ||
case boost::real::OPERATION::MULTIPLICATION: | ||
lhs *= rhs; | ||
break; | ||
} | ||
} | ||
|
||
class NullStream: public std::ostream | ||
{ | ||
public: | ||
NullStream() : std::ostream(&sb) {} | ||
enum class Comparison {greater_than, less_than, equals}; | ||
constexpr bool realComp(boost::real::real& lhs,boost::real::real& rhs, Comparison comp) { | ||
switch (comp) { | ||
case (Comparison::greater_than): | ||
return lhs > rhs; | ||
case (Comparison::less_than): | ||
return lhs < rhs; | ||
case(Comparison::equals): | ||
return lhs==rhs; | ||
} | ||
} | ||
|
||
private: | ||
NullBuffer sb; | ||
}; | ||
#endif // BOOST_REAL_BENCHMARK_HELPERS_HPP |
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,8 @@ | ||
#include <benchmark/benchmark.h> | ||
#include <real/real.hpp> | ||
|
||
// ensure this is >= to MAX_NUM_DIGITS_XX for all benchmarks, else we will get | ||
// a precision error and the benchmarks will not be meaningful. | ||
std::optional<unsigned int> boost::real::const_precision_iterator::maximum_precision = 10000; | ||
|
||
BENCHMARK_MAIN(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
#include <benchmark/benchmark.h> | ||
#include <benchmark_helpers.hpp> | ||
|
||
/** benchmarks the construction of a real number | ||
* for some varying parameter | ||
* (number of tree nodes, or number of digits) | ||
*/ | ||
|
||
const int MIN_TREE_NODES = 10; | ||
const int MAX_TREE_NODES = 10000; | ||
const int MULTIPLIER_TC = 10; // for range evaluation of tree construction benchmarks | ||
/// benchmarks the construction speed of doing a op= b, n times, where n is the set of powers of | ||
/// MULTIPLIER_TC between MIN_TREE_NODES and MAX_TREE_NODES | ||
void BM_RealOperationTreeConstruction(benchmark::State& state, boost::real::OPERATION op) { | ||
for (auto i : state) { | ||
boost::real::real a ("1234567891"); | ||
boost::real::real b ("9876532198"); | ||
|
||
// We keep the precision constant here because in constructing the *= tree, we would get way more digits | ||
// than in +=, -= trees. This should make the benchmarks more meaningful | ||
a.set_maximum_precision(10); | ||
|
||
for (int i = 0; i < state.range(0); i++) | ||
realOperationEq(a,b,op); | ||
|
||
state.SetComplexityN(state.range(0)); | ||
} | ||
} | ||
|
||
// these benchmark the operation tree constructors for each operation type. | ||
/// @TODO: add division bench | ||
BENCHMARK_CAPTURE(BM_RealOperationTreeConstruction, addition, boost::real::OPERATION(boost::real::OPERATION::ADDITION)) | ||
->RangeMultiplier(MULTIPLIER_TC)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationTreeConstruction, subtraction, boost::real::OPERATION(boost::real::OPERATION::SUBTRACTION)) | ||
->RangeMultiplier(MULTIPLIER_TC)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationTreeConstruction, multiplication, boost::real::OPERATION(boost::real::OPERATION::MULTIPLICATION)) | ||
->RangeMultiplier(MULTIPLIER_TC)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
const int MIN_NUM_DIGITS_EC = 10; | ||
const int MAX_NUM_DIGITS_EC = 10000; | ||
const int MULTIPLIER_EC = 10; // for range evaluation of explicit construction benchmarks | ||
|
||
/// benchmarks real explicit's string constructor for a varying number of digits | ||
void BM_RealExplicitConstruction_String(benchmark::State& state) { | ||
for (auto i : state) { | ||
state.PauseTiming(); // construct a string representing a number of n digits | ||
std::string number; | ||
|
||
for (int i = 0; i < state.range(0); i++) { | ||
number.push_back('1'); | ||
} | ||
state.ResumeTiming(); | ||
|
||
boost::real::real a(number); | ||
state.SetComplexityN(state.range(0)); | ||
} | ||
} | ||
BENCHMARK(BM_RealExplicitConstruction_String) | ||
->RangeMultiplier(MULTIPLIER_EC)->Range(MIN_NUM_DIGITS_EC,MAX_NUM_DIGITS_EC)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
// benchmarks for real_algorithm construction seem unnecessary because there's not much that goes on in it |
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 @@ | ||
#include <benchmark/benchmark.h> | ||
#include <benchmark_helpers.hpp> | ||
|
||
const int MIN_TREE_NODES = 10; | ||
const int MAX_TREE_NODES = 10000; | ||
const int MULTIPLIER_TE = 10; // for range evaluation of tree evaluation benchmarks | ||
|
||
/// benchmarks the evaluation speed of doing a op= b, n times, where n is the set of powers of | ||
/// MULTIPLIER_TE between MIN_TREE_NODES and MAX_TREE_NODES | ||
void BM_RealOperationTreeEvaluation(benchmark::State& state, boost::real::OPERATION op) { | ||
for (auto i : state) { | ||
boost::real::real a ("12"); | ||
boost::real::real b ("34"); | ||
|
||
state.PauseTiming(); | ||
for (int i = 0; i < state.range(0); i++) { | ||
realOperationEq(a,b,op); | ||
} | ||
state.ResumeTiming(); | ||
|
||
a.get_real_itr().cend(); // force evaluation | ||
state.SetComplexityN(state.range(0)); | ||
} | ||
} | ||
|
||
/// @TODO: add division. | ||
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, addition, boost::real::OPERATION(boost::real::OPERATION::ADDITION)) | ||
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, subtraction, boost::real::OPERATION(boost::real::OPERATION::SUBTRACTION)) | ||
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationTreeEvaluation, multiplication, boost::real::OPERATION(boost::real::OPERATION::MULTIPLICATION)) | ||
->RangeMultiplier(MULTIPLIER_TE)->Range(MIN_TREE_NODES ,MAX_TREE_NODES)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
|
||
const int MIN_NUM_DIGITS = 1000; | ||
const int MAX_NUM_DIGITS = 10000; | ||
const int MULTIPLIER_OE = 6; | ||
|
||
/// benchmarks a op= b, where a, b, have n digits, where n is the set of powers of | ||
/// MULTIPLIER_OE, between MIN_NUM_DIGITS and MAX_NUM_DIGITS | ||
void BM_RealOperationEvaluation(benchmark::State& state, boost::real::OPERATION op) { | ||
for (auto i : state) { | ||
state.PauseTiming(); // construct a, b | ||
std::string tmp; | ||
for (int i = 0; i < state.range(0); i++) { | ||
tmp.push_back('2'); | ||
} | ||
boost::real::real a(tmp); | ||
|
||
tmp.clear(); | ||
for (int i = 0; i < state.range(0); i++) { | ||
tmp.push_back('3'); | ||
} | ||
boost::real::real b(tmp); | ||
realOperationEq(a,b,op); | ||
state.ResumeTiming(); | ||
|
||
a.get_real_itr().cend(); // force evaluation | ||
state.SetComplexityN(state.range(0)); | ||
} | ||
} | ||
|
||
///@TODO: add division | ||
// The BM_RealOperationEvaluation operations are much faster, so these use nanoseconds in the result. | ||
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, addition, boost::real::OPERATION(boost::real::OPERATION::ADDITION)) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, subtraction, boost::real::OPERATION(boost::real::OPERATION::SUBTRACTION)) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealOperationEvaluation, multiplication, boost::real::OPERATION(boost::real::OPERATION::MULTIPLICATION)) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS) | ||
->Complexity(); | ||
|
||
|
||
/// benchmarks operator> operator< and operator== for numbers a, b, where a == b, with n digits | ||
void BM_RealComparisonEvaluation(benchmark::State& state, Comparison comp) { | ||
for (auto i : state) { | ||
state.PauseTiming(); // construct a, b | ||
std::string tmp; | ||
for (int i = 0; i < state.range(0); i++) { // we compare 111...1 and 111..1 | ||
tmp.push_back('1'); | ||
} | ||
boost::real::real a(tmp); | ||
boost::real::real b(tmp); | ||
|
||
state.ResumeTiming(); | ||
|
||
bool boo = realComp(a,b,comp); // evaluation | ||
state.SetComplexityN(state.range(0)); | ||
} | ||
} | ||
|
||
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, less_than, Comparison::less_than) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, greater_than, Comparison::greater_than) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond) | ||
->Complexity(); | ||
|
||
BENCHMARK_CAPTURE(BM_RealComparisonEvaluation, equals, Comparison::equals) | ||
->RangeMultiplier(MULTIPLIER_OE)->Range(MIN_NUM_DIGITS,MAX_NUM_DIGITS)->Unit(benchmark::kMillisecond) | ||
->Complexity(); |
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
Oops, something went wrong.