improved benchmarking

This commit is contained in:
ThePhD 2016-01-16 02:30:49 -05:00
parent 60b91b4c83
commit 8c9f8c3341
6 changed files with 133 additions and 18 deletions

View File

@ -2,6 +2,7 @@
#include "bench_lua_function.hpp"
#include "bench_get.hpp"
#include "bench_set.hpp"
#include "bench_usertype.hpp"
#include "nonius/nonius.h++"
int main( int argc, char* argv[] ) {
@ -12,4 +13,5 @@ int main( int argc, char* argv[] ) {
bench_cpp_function( "bench/", configurationname, platformname );
bench_get( "bench/", configurationname, platformname );
bench_set( "bench/", configurationname, platformname );
bench_usertype( "bench/", configurationname, platformname );
}

View File

@ -1 +0,0 @@
#pragma once

105
bench_usertype.hpp Normal file
View File

@ -0,0 +1,105 @@
#pragma once
#include "sol.hpp"
#include "nonius/nonius.h++"
struct woof {
int var;
int func( int x ) {
return var + x;
}
int operator + (int x) const {
return var + x;
}
};
static sol::state prepare_usertype_state( ) {
sol::state lua;
lua.new_usertype<woof>( "woof",
"var", &woof::var,
"func", &woof::func,
sol::meta_function::addition, &woof::operator+ );
lua.script( R"(
r = woof:new()
)" );
return lua;
}
struct sol_usertype_special_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
auto measurement = [ & ] ( int run_index ) {
lua.script("x = r + 2");
};
meter.measure( measurement );
}
};
struct sol_usertype_regular_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
auto measurement = [ & ] ( int run_index ) {
lua.script("x = r:func( 2 )");
};
meter.measure( measurement );
}
};
struct sol_usertype_variable_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
auto measurement = [ & ] ( int run_index ) {
lua.script("x = r.var + 2");
};
meter.measure( measurement );
}
};
struct c_usertype_special_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
lua_State* L = lua.lua_state( );
auto measurement = [ & ] ( int run_index ) {
};
meter.measure( measurement );
}
};
struct c_usertype_regular_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
lua_State* L = lua.lua_state( );
auto measurement = [ & ] ( int run_index ) {
};
meter.measure( measurement );
}
};
struct c_usertype_variable_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua = prepare_usertype_state( );
lua_State* L = lua.lua_state( );
auto measurement = [ & ] ( int run_index ) {
};
meter.measure( measurement );
}
};
void bench_usertype( const std::string& dir, std::string& configurationname, const std::string& platformname ) {
nonius::configuration cfg;
cfg.output_file = dir + "sol.usertype - " + configurationname + " " + platformname + ".html";
cfg.title = "sol usertype (" + configurationname + " " + platformname + ")";
cfg.samples = 100;
nonius::benchmark benchmarks [] = {
nonius::benchmark( "sol - usertype special", sol_usertype_special_bench( ) ),
nonius::benchmark( "sol - usertype regular", sol_usertype_regular_bench( ) ),
nonius::benchmark( "sol - usertype variable", sol_usertype_variable_bench( ) ),
//nonius::benchmark( "plain C - usertype special", c_usertype_special_bench( ) ),
//nonius::benchmark( "plain C - usertype regular", c_usertype_regular_bench( ) ),
//nonius::benchmark( "plain C - usertype variable", c_usertype_variable_bench( ) ),
};
nonius::go( cfg, std::begin( benchmarks ), std::end( benchmarks ), nonius::html_reporter( ) );
}

View File

@ -63,7 +63,7 @@ public:
}
template<typename T>
T get() const {
decltype(auto) get() const {
return tbl.template get<T>( key );
}
@ -71,19 +71,19 @@ public:
return get<std::string>();
}
template<typename T, EnableIf<Not<std::is_same<Unqualified<T>, const char*>>, Not<std::is_same<Unqualified<T>, char>>, Not<std::is_same<Unqualified<T>, std::string>>, Not<std::is_same<Unqualified<T>, std::initializer_list<char>>>> = 0>
operator T () const {
return get<T>();
template<typename T, EnableIf<Not<is_string_constructible<T>>, is_lua_primitive<T>> = 0>
operator T ( ) const {
return get<T>( );
}
template<typename T, EnableIf<Not<is_string_constructible<T>>, Not<is_lua_primitive<T>>> = 0>
operator T& ( ) const {
return get<T&>( );
}
template<typename... Ret, typename... Args>
stack::get_return_or<function_result, Ret...> call(Args&&... args) {
return tbl.template get<function>(key)(types<Ret...>(), std::forward<Args>(args)...);
}
template<typename... Args>
function_result operator()(Args&&... args) {
return tbl.template get<function>(key)(std::forward<Args>(args)...);
decltype(auto) call(Args&&... args) {
return get<function>().call<Ret...>(std::forward<Args>(args)...);
}
};

View File

@ -87,7 +87,7 @@ template<typename T, typename... Args>
struct And<T, Args...> : If<T, And<Args...>, Bool<false>> {};
template<typename... Args>
struct Or : Bool<true> {};
struct Or : Bool<false> {};
template<typename T, typename... Args>
struct Or<T, Args...> : If<T, Bool<true>, Or<Args...>> {};
@ -311,6 +311,9 @@ struct has_key_value_pair_impl {
template<typename T>
struct has_key_value_pair : decltype(has_key_value_pair_impl::test<T>(0)) {};
template <typename T>
using is_string_constructible = Or<std::is_same<Unqualified<T>, const char*>, std::is_same<Unqualified<T>, char>, std::is_same<Unqualified<T>, std::string>, std::is_same<Unqualified<T>, std::initializer_list<char>>>;
template<typename T>
auto unwrapper(T&& item) -> decltype(std::forward<T>(item)) {
return std::forward<T>(item);

View File

@ -32,9 +32,6 @@ const nil_t nil {};
inline bool operator==(nil_t, nil_t) { return true; }
inline bool operator!=(nil_t, nil_t) { return false; }
struct void_type : types<void> {}; // This is important because it allows myobject.call( Void, ... ) to work
const void_type Void {};
template<typename... T>
struct function_sig_t {};
using function_t = function_sig_t<>;
@ -146,10 +143,13 @@ template <>
struct lua_type_of<bool> : std::integral_constant<type, type::boolean> {};
template <>
struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> {};
struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> { };
template <>
struct lua_type_of<table> : std::integral_constant<type, type::table> {};
struct lua_type_of<table> : std::integral_constant<type, type::table> { };
template <>
struct lua_type_of<global_table> : std::integral_constant<type, type::table> { };
template <>
struct lua_type_of<object> : std::integral_constant<type, type::poly> {};
@ -160,6 +160,9 @@ struct lua_type_of<light_userdata> : std::integral_constant<type, type::lightuse
template <>
struct lua_type_of<function> : std::integral_constant<type, type::function> {};
template <>
struct lua_type_of<fast_function> : std::integral_constant<type, type::function> {};
template <typename Signature>
struct lua_type_of<std::function<Signature>> : std::integral_constant<type, type::function>{};
@ -185,6 +188,9 @@ struct lua_type_of<T, typename std::enable_if<std::is_enum<T>::value>::type> : s
};
template <typename T>
struct is_lua_primitive : std::integral_constant<bool, type::userdata != lua_type_of<Unqualified<T>>::value> { };
} // sol
#endif // SOL_TYPES_HPP