-
Notifications
You must be signed in to change notification settings - Fork 69
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
Nanobenchmarks #4143
Merged
Merged
Nanobenchmarks #4143
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d8e341f
nanobenchmarks
eggrobin f11e934
configurable quantiles, std::print etc.
eggrobin b1b7221
perf boost mode
eggrobin 704e429
perf boost mode in its own class
eggrobin 472eb12
split things
eggrobin c3b3502
meow
eggrobin 5026a76
more flags
eggrobin 66e5e77
invert
eggrobin 0a811f4
cbrt to examples
eggrobin b18890d
missing file
eggrobin bc6860e
make it build
eggrobin b04ec62
I forgot to pull…
eggrobin f501734
eggspected
eggrobin c8ad1eb
μarch
eggrobin 0c05aa6
lint
eggrobin 64b6d8e
throttling
eggrobin 1b9982a
More review comments
eggrobin 5165417
format bibliography
eggrobin 2fbe62b
regenerate bibliography
eggrobin f806daa
reorder
eggrobin 5c7c521
New
eggrobin c969067
blank lines, PROCESSOR_PROCESSOR
eggrobin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use absl maps everywhere.
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.
These are ordered, so that the tests show up in alphabetical(ish) order; we don’t use absl ordered maps unless we have a good reason to.