mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
More hot, steamy benchmarks.
This commit is contained in:
parent
48e2c82203
commit
60b91b4c83
|
@ -1,5 +1,7 @@
|
|||
#include "bench_cpp_function.hpp"
|
||||
#include "bench_lua_function.hpp"
|
||||
#include "bench_get.hpp"
|
||||
#include "bench_set.hpp"
|
||||
#include "nonius/nonius.h++"
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
|
@ -8,4 +10,6 @@ int main( int argc, char* argv[] ) {
|
|||
std::string platformname = argv[ 2 ];
|
||||
bench_lua_function( "bench/", configurationname, platformname );
|
||||
bench_cpp_function( "bench/", configurationname, platformname );
|
||||
bench_get( "bench/", configurationname, platformname );
|
||||
bench_set( "bench/", configurationname, platformname );
|
||||
}
|
|
@ -1 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
#include "sol.hpp"
|
||||
#include "nonius/nonius.h++"
|
||||
|
||||
static sol::state prepare_get_state( ) {
|
||||
sol::state lua;
|
||||
lua.set( "r", 25 );
|
||||
return lua;
|
||||
}
|
||||
|
||||
struct sol_get_proxy_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_get_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
int value = lua[ "r" ];
|
||||
return value;
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
struct sol_get_typed_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_get_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
int value = lua.get<int>( "r" );
|
||||
return value;
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
struct c_get_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_get_state( );
|
||||
lua_State* L = lua.lua_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
lua_getglobal( L, "r" );
|
||||
int value = (int)lua_tonumber( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
return value;
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
void bench_get( const std::string& dir, std::string& configurationname, const std::string& platformname ) {
|
||||
nonius::configuration cfg;
|
||||
cfg.output_file = dir + "sol.get - " + configurationname + " " + platformname + ".html";
|
||||
cfg.title = "sol get (" + configurationname + " " + platformname + ")";
|
||||
cfg.samples = 100;
|
||||
nonius::benchmark benchmarks [] = {
|
||||
nonius::benchmark( "sol - proxy get", sol_get_proxy_bench( ) ),
|
||||
nonius::benchmark( "sol - typed get", sol_get_typed_bench( ) ),
|
||||
nonius::benchmark( "plain C", c_get_bench( ) ),
|
||||
};
|
||||
nonius::go( cfg, std::begin( benchmarks ), std::end( benchmarks ), nonius::html_reporter( ) );
|
||||
}
|
||||
|
|
|
@ -1 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
#include "sol.hpp"
|
||||
#include "nonius/nonius.h++"
|
||||
|
||||
static sol::state prepare_set_state( ) {
|
||||
sol::state lua;
|
||||
lua.set( "r", 25 );
|
||||
return lua;
|
||||
}
|
||||
|
||||
struct sol_set_proxy_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_set_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
lua[ "r" ] = 40;
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
struct sol_set_typed_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_set_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
lua.set( "r", 40 );
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
struct c_set_bench {
|
||||
void operator () ( nonius::chronometer meter ) const {
|
||||
sol::state lua = prepare_set_state( );
|
||||
lua_State* L = lua.lua_state( );
|
||||
auto measurement = [ & ] ( int run_index ) {
|
||||
lua_pushinteger( L, 40 );
|
||||
lua_setglobal( L, "r" );
|
||||
};
|
||||
meter.measure( measurement );
|
||||
}
|
||||
};
|
||||
|
||||
void bench_set( const std::string& dir, std::string& configurationname, const std::string& platformname ) {
|
||||
nonius::configuration cfg;
|
||||
cfg.output_file = dir + "sol.set - " + configurationname + " " + platformname + ".html";
|
||||
cfg.title = "sol set (" + configurationname + " " + platformname + ")";
|
||||
cfg.samples = 100;
|
||||
nonius::benchmark benchmarks [] = {
|
||||
nonius::benchmark( "sol - proxy set", sol_set_proxy_bench( ) ),
|
||||
nonius::benchmark( "sol - typed set", sol_set_typed_bench( ) ),
|
||||
nonius::benchmark( "plain C", c_set_bench( ) ),
|
||||
};
|
||||
nonius::go( cfg, std::begin( benchmarks ), std::end( benchmarks ), nonius::html_reporter( ) );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user