@@ -110,6 +110,8 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
110110 CaseResult freeCall;
111111 CaseResult memberCall;
112112 CaseResult property;
113+ CaseResult propertySet;
114+ CaseResult propertyGet;
113115 CaseResult cppGlobalGet;
114116 CaseResult cppGlobalSet;
115117 CaseResult cppTableGet;
@@ -131,17 +133,21 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
131133 const std::string freeCallLoop = " for i = 1, " + std::to_string (iterations) + " do add(i, i) end" ;
132134 const std::string memberCallLoop = " for i = 1, " + std::to_string (iterations) + " do obj:inc() end" ;
133135 const std::string propertyLoop = " for i = 1, " + std::to_string (iterations) + " do obj.value = i; local x = obj.value end" ;
136+ const std::string propertySetLoop = " for i = 1, " + std::to_string (iterations) + " do obj.value = i end" ;
137+ const std::string propertyGetLoop = " local s = 0; for i = 1, " + std::to_string (iterations) + " do s = s + obj.value end" ;
134138
135139 empty = runCase (" lua_empty_loop" , iterations, [&] { doLua (emptyLoop.c_str ()); });
136140 freeCall = runCase (" lua_to_cpp_free_fn" , iterations, [&] { doLua (freeCallLoop.c_str ()); });
137141 memberCall = runCase (" lua_to_cpp_member" , iterations, [&] { doLua (memberCallLoop.c_str ()); });
138142 property = runCase (" lua_to_cpp_property" , iterations, [&] { doLua (propertyLoop.c_str ()); });
143+ propertySet = runCase (" lua_to_cpp_property_set" , iterations, [&] { doLua (propertySetLoop.c_str ()); });
144+ propertyGet = runCase (" lua_to_cpp_property_get" , iterations, [&] { doLua (propertyGetLoop.c_str ()); });
139145
140146 cppGlobalGet = runCase (" cpp_table_global_get" , iterations, [&]
141147 {
142148 double x = 0.0 ;
143149 for (std::int64_t i = 0 ; i < iterations; ++i)
144- x += static_cast < double >( luabridge::getGlobal (L, " gvalue" ) );
150+ x += * luabridge::getGlobal< double > (L, " gvalue" );
145151 sink = x;
146152 });
147153
@@ -161,7 +167,7 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
161167 {
162168 double x = 0.0 ;
163169 for (std::int64_t i = 0 ; i < iterations; ++i)
164- x += static_cast <double >(tableRef[ " value" ] );
170+ x += tableRef. unsafeRawgetField <double >(" value" );
165171 sink = x;
166172 });
167173
@@ -171,17 +177,17 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
171177 for (std::int64_t i = 0 ; i < iterations; ++i)
172178 {
173179 v += 1.0 ;
174- tableRef[ " value" ] = v ;
180+ tableRef. unsafeRawsetField ( " value" , v) ;
175181 }
176- sink = static_cast <double >(tableRef[ " value" ] );
182+ sink = tableRef. unsafeRawgetField <double >(" value" );
177183 });
178184
179185 const auto chainRef = luabridge::getGlobal (L, " chain" );
180186 cppChainedGet = runCase (" cpp_table_chained_get" , iterations, [&]
181187 {
182188 double x = 0.0 ;
183189 for (std::int64_t i = 0 ; i < iterations; ++i)
184- x += static_cast < double >( chainRef[" inner" ][ " value" ] );
190+ x += chainRef[" inner" ]. unsafeRawgetField < double >( " value" );
185191 sink = x;
186192 });
187193
@@ -191,9 +197,10 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
191197 for (std::int64_t i = 0 ; i < iterations; ++i)
192198 {
193199 v += 1.0 ;
194- chainRef[" inner" ][ " value" ] = v ;
200+ chainRef[" inner" ]. unsafeRawsetField ( " value" , v) ;
195201 }
196- sink = static_cast <double >(chainRef[" inner" ][" value" ]);
202+
203+ sink = chainRef[" inner" ].unsafeRawgetField <double >(" value" );
197204 });
198205
199206 doLua (" function f(a, b) return a + b end" );
@@ -219,6 +226,8 @@ void runLuaBridgeBenchmarks(std::int64_t iterations)
219226 printResult (" LuaBridge" , freeCall);
220227 printResult (" LuaBridge" , memberCall);
221228 printResult (" LuaBridge" , property);
229+ printResult (" LuaBridge" , propertySet);
230+ printResult (" LuaBridge" , propertyGet);
222231 printResult (" LuaBridge" , cppGlobalGet);
223232 printResult (" LuaBridge" , cppGlobalSet);
224233 printResult (" LuaBridge" , cppTableGet);
@@ -259,11 +268,15 @@ void runSol2Benchmarks(std::int64_t iterations)
259268 const std::string freeCallLoop = " for i = 1, " + std::to_string (iterations) + " do add(i, i) end" ;
260269 const std::string memberCallLoop = " for i = 1, " + std::to_string (iterations) + " do obj:inc() end" ;
261270 const std::string propertyLoop = " for i = 1, " + std::to_string (iterations) + " do obj.value = i; local x = obj.value end" ;
271+ const std::string propertySetLoop = " for i = 1, " + std::to_string (iterations) + " do obj.value = i end" ;
272+ const std::string propertyGetLoop = " local s = 0; for i = 1, " + std::to_string (iterations) + " do s = s + obj.value end" ;
262273
263274 const auto empty = runCase (" lua_empty_loop" , iterations, [&] { lua.script (emptyLoop); });
264275 const auto freeCall = runCase (" lua_to_cpp_free_fn" , iterations, [&] { lua.script (freeCallLoop); });
265276 const auto memberCall = runCase (" lua_to_cpp_member" , iterations, [&] { lua.script (memberCallLoop); });
266277 const auto property = runCase (" lua_to_cpp_property" , iterations, [&] { lua.script (propertyLoop); });
278+ const auto propertySet = runCase (" lua_to_cpp_property_set" , iterations, [&] { lua.script (propertySetLoop); });
279+ const auto propertyGet = runCase (" lua_to_cpp_property_get" , iterations, [&] { lua.script (propertyGetLoop); });
267280
268281 const auto cppGlobalGet = runCase (" cpp_table_global_get" , iterations, [&]
269282 {
@@ -325,14 +338,14 @@ void runSol2Benchmarks(std::int64_t iterations)
325338 });
326339
327340 lua.script (" function f(a, b) return a + b end" );
328- sol::function f = lua[" f" ];
341+ sol::protected_function f = lua[" f" ];
329342 const auto cppToLua = runCase (" cpp_to_lua_call" , iterations, [&]
330343 {
331344 for (std::int64_t i = 0 ; i < iterations; ++i)
332345 (void ) f (static_cast <int >(i), static_cast <int >(i));
333346 });
334347
335- sol::function addFn = lua[" add" ];
348+ sol::protected_function addFn = lua[" add" ];
336349 const auto cppCFunctionThroughLua = runCase (" cpp_c_function_through_lua" , iterations, [&]
337350 {
338351 int x = 0 ;
@@ -345,6 +358,8 @@ void runSol2Benchmarks(std::int64_t iterations)
345358 printResult (" sol2" , freeCall);
346359 printResult (" sol2" , memberCall);
347360 printResult (" sol2" , property);
361+ printResult (" sol2" , propertySet);
362+ printResult (" sol2" , propertyGet);
348363 printResult (" sol2" , cppGlobalGet);
349364 printResult (" sol2" , cppGlobalSet);
350365 printResult (" sol2" , cppTableGet);
0 commit comments