-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4143 from eggrobin/nanobenchmarks
Nanobenchmarks
- Loading branch information
Showing
14 changed files
with
1,055 additions
and
29 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
Binary file not shown.
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,58 @@ | ||
#include <emmintrin.h> | ||
|
||
#include "nanobenchmarks/function_registry.hpp" | ||
#include "numerics/cbrt.hpp" | ||
|
||
namespace principia { | ||
namespace nanobenchmarks { | ||
namespace _examples { | ||
|
||
using namespace principia::numerics::_cbrt; | ||
|
||
BENCHMARKED_FUNCTION(twice) { | ||
return 2 * x; | ||
} | ||
|
||
BENCHMARKED_FUNCTION(thrice) { | ||
return 3 * x; | ||
} | ||
|
||
BENCHMARKED_FUNCTION(inc) { | ||
return x + 1; | ||
} | ||
|
||
BENCHMARKED_FUNCTION(add_4_times) { | ||
return x * x * x * x * x; | ||
} | ||
|
||
BENCHMARKED_FUNCTION(add_16_times) { | ||
return x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x; | ||
} | ||
|
||
BENCHMARKED_FUNCTION(square_root) { | ||
__m128d x_0 = _mm_set_sd(x); | ||
return _mm_cvtsd_f64(_mm_sqrt_sd(x_0, x_0)); | ||
} | ||
|
||
BENCHMARKED_FUNCTION(sqrt_sqrt) { | ||
__m128d x_0 = _mm_set_sd(x); | ||
x_0 = _mm_sqrt_sd(x_0, x_0); | ||
return _mm_cvtsd_f64(_mm_sqrt_sd(x_0, x_0)); | ||
} | ||
|
||
BENCHMARKED_FUNCTION(square_root_division) { | ||
__m128d x_0 = _mm_set_sd(x); | ||
return _mm_cvtsd_f64(_mm_div_sd(x_0, _mm_sqrt_sd(x_0, x_0))); | ||
} | ||
BENCHMARK_FUNCTION(Cbrt); | ||
|
||
using namespace principia::numerics::_cbrt::internal; | ||
|
||
BENCHMARK_FUNCTION(method_3²ᴄZ5¹::Cbrt<Rounding::Faithful>); | ||
BENCHMARK_FUNCTION(method_3²ᴄZ5¹::Cbrt<Rounding::Correct>); | ||
BENCHMARK_FUNCTION(method_5²Z4¹FMA::Cbrt<Rounding::Faithful>); | ||
BENCHMARK_FUNCTION(method_5²Z4¹FMA::Cbrt<Rounding::Correct>); | ||
|
||
} // namespace _examples | ||
} // namespace nanobenchmarks | ||
} // namespace principia |
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,42 @@ | ||
#include "nanobenchmarks/function_registry.hpp" | ||
|
||
#include <functional> | ||
#include <map> | ||
#include <string> | ||
|
||
#include "glog/logging.h" | ||
|
||
namespace principia { | ||
namespace nanobenchmarks { | ||
namespace _function_registry { | ||
namespace internal { | ||
|
||
bool FunctionRegistry::Register(std::string_view name, | ||
BenchmarkedFunction function) { | ||
CHECK(singleton_.names_by_function_.emplace(function, name).second) | ||
<< " Registering function " << function << " as " << name << ": " | ||
<< "function already registered as " | ||
<< singleton_.names_by_function_[function]; | ||
CHECK(singleton_.functions_by_name_.emplace(name, function).second) | ||
<< " Registering function " << function << " as " << name << ": " | ||
<< " name already taken by " | ||
<< singleton_.functions_by_name_.find(name)->second; | ||
return true; | ||
} | ||
|
||
FunctionRegistry& FunctionRegistry::singleton_ = *new FunctionRegistry(); | ||
|
||
std::map<std::string, BenchmarkedFunction, std::less<>> const& | ||
FunctionRegistry::functions_by_name() { | ||
return singleton_.functions_by_name_; | ||
} | ||
|
||
std::map<BenchmarkedFunction, std::string> const& | ||
FunctionRegistry::names_by_function() { | ||
return singleton_.names_by_function_; | ||
} | ||
|
||
} // namespace internal | ||
} // namespace _function_registry | ||
} // namespace nanobenchmarks | ||
} // namespace principia |
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,61 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <map> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include "base/macros.hpp" | ||
|
||
namespace principia { | ||
namespace nanobenchmarks { | ||
namespace _function_registry { | ||
namespace internal { | ||
|
||
using BenchmarkedFunction = double (*)(double); | ||
|
||
class FunctionRegistry { | ||
public: | ||
static bool Register(std::string_view name, BenchmarkedFunction function); | ||
static std::map<std::string, BenchmarkedFunction, std::less<>> const& | ||
functions_by_name(); | ||
static std::map<BenchmarkedFunction, std::string> const& names_by_function(); | ||
|
||
private: | ||
FunctionRegistry() = default; | ||
static FunctionRegistry& singleton_; | ||
std::map<std::string, BenchmarkedFunction, std::less<>> functions_by_name_; | ||
std::map<BenchmarkedFunction, std::string> names_by_function_; | ||
}; | ||
|
||
#define BENCHMARK_FUNCTION_WITH_NAME(name, ...) \ | ||
BENCHMARK_FUNCTION_WITH_NAME_INTERNAL(__LINE__, name, __VA_ARGS__) | ||
#define BENCHMARK_FUNCTION_WITH_NAME_INTERNAL(line, name, ...) \ | ||
BENCHMARK_FUNCTION_WITH_NAME_INTERNAL2(line, name, __VA_ARGS__) | ||
#define BENCHMARK_FUNCTION_WITH_NAME_INTERNAL2(line, name, ...) \ | ||
namespace { \ | ||
static bool registered##line = ::principia::nanobenchmarks:: \ | ||
_function_registry::FunctionRegistry::Register(name, &(__VA_ARGS__)); \ | ||
} | ||
|
||
|
||
#define BENCHMARK_FUNCTION(...) \ | ||
BENCHMARK_FUNCTION_WITH_NAME(#__VA_ARGS__, __VA_ARGS__) | ||
|
||
#define BENCHMARKED_FUNCTION(f) \ | ||
double f(double x); \ | ||
BENCHMARK_FUNCTION(f); \ | ||
double f(double x) | ||
|
||
#define BENCHMARK_EXTERN_C_FUNCTION(f) \ | ||
extern "C" double f(double); \ | ||
BENCHMARK_FUNCTION(f) | ||
|
||
} // namespace internal | ||
|
||
using internal::BenchmarkedFunction; | ||
using internal::FunctionRegistry; | ||
|
||
} // namespace _function_registry | ||
} // namespace nanobenchmarks | ||
} // namespace principia |
Oops, something went wrong.