diff --git a/CMakeLists.txt b/CMakeLists.txt index 841615f..07af575 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -397,6 +397,14 @@ if(BUILD_TESTING) add_test(NAME performance.${filename} COMMAND ${VALGRIND} --tool=callgrind --callgrind-out-file=callgrind.performance.${filename} $ ${CMAKE_CURRENT_SOURCE_DIR}/performance_tests/${filename}) list(APPEND TESTS performance.${filename}) endforeach() + + add_executable(profile_cpp_calls_2 performance_tests/profile_cpp_calls_2.cpp) + target_link_libraries(profile_cpp_calls_2 ${LIBS}) + add_test(NAME performance.profile_cpp_calls_2 COMMAND ${VALGRIND} --tool=callgrind --callgrind-out-file=callgrind.performance.profile_cpp_calls_2 $) + + add_executable(profile_fun_wrappers performance_tests/profile_fun_wrappers.cpp) + target_link_libraries(profile_fun_wrappers ${LIBS}) + add_test(NAME performance.profile_fun_wrappers COMMAND ${VALGRIND} --tool=callgrind --callgrind-out-file=callgrind.performance.profile_fun_wrappers $) endif() set_property(TEST ${TESTS} diff --git a/performance_tests/profile_cpp_calls_2.cpp b/performance_tests/profile_cpp_calls_2.cpp new file mode 100644 index 0000000..0424654 --- /dev/null +++ b/performance_tests/profile_cpp_calls_2.cpp @@ -0,0 +1,20 @@ +#include +#include + +double f(const std::string &, double, bool) noexcept { + return .0; +} + +int main() +{ + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + + chai.add(chaiscript::fun(&f), "f"); + + chai.eval(R"( + for (var i = 0; i < 100000; ++i) { + f("str", 1.2, false); + } + )"); + +} diff --git a/performance_tests/profile_fun_wrappers.cpp b/performance_tests/profile_fun_wrappers.cpp new file mode 100644 index 0000000..fb96f48 --- /dev/null +++ b/performance_tests/profile_fun_wrappers.cpp @@ -0,0 +1,20 @@ +#include +#include + +double f(const std::string &, double, bool) noexcept { + return .0; +} + +int main() +{ + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + + chai.add(chaiscript::fun(&f), "f"); + + const auto f = chai.eval>(R"(fun(){ f("str", 1.2, false); })"); + + for (int i = 0; i < 100000; ++i) { + f(); + } + +}