Last active
February 11, 2020 08:29
-
-
Save facontidavide/e9fdfa1e929fb61142c6d3300f2512c6 to your computer and use it in GitHub Desktop.
Lua vs QT JS
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
#include <iostream> | |
#include <QJSEngine> | |
#include "sol.hpp" //https://github.com/ThePhD/sol2 | |
#include <benchmark/benchmark.h> | |
static void QmlFunction(benchmark::State& state) { | |
QJSEngine js; | |
js.evaluate("function calc(time, value){ return value*2 }"); | |
QJSValue func = js.evaluate("calc"); | |
for (auto _ : state) { | |
QJSValue result = func.call({QJSValue(1), QJSValue(2)}); | |
benchmark::DoNotOptimize(result.toNumber()); | |
} | |
} | |
BENCHMARK(QmlFunction); | |
static void LuaFunction(benchmark::State& state) { | |
sol::state lua; | |
lua.open_libraries(); | |
lua.script("function calc(time, value) return value*2 end"); | |
sol::function func = lua["calc"]; | |
for (auto _ : state) { | |
sol::function_result result = func(1, 2); | |
benchmark::DoNotOptimize(result.get<double>(0)); | |
} | |
} | |
BENCHMARK(LuaFunction); | |
/* | |
* ------------------------------------------------------ | |
Benchmark Time CPU Iterations | |
------------------------------------------------------ | |
QmlFunction 498 ns 498 ns 1379603 | |
LuaFunction 74.2 ns 74.2 ns 9476946 | |
*/ | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment