10 #define LUABIND_NO_ERROR_CHECKING
11 #define LUABIND_DONT_COPY_STRINGS
12 //#define LUABIND_NOT_THREADSAFE
20 #include <luabind/luabind.hpp>
25 float f1(int a
, float b
, const char* str
, A
* c
)
39 const int num_calls
= 100000;
42 using namespace luabind
;
44 lua_State
* L
= lua_open();
48 .def(constructor
<>());
50 function(L
, "test1", &f1
);
52 lua_pushstring(L
, "test2");
53 lua_pushcclosure(L
, &f2
, 0);
54 lua_settable(L
, LUA_GLOBALSINDEX
);
56 std::clock_t total1
= 0;
57 std::clock_t total2
= 0;
59 for (int i
= 0; i
< loops
; ++i
)
62 std::clock_t start1
= std::clock();
63 lua_dostring(L
, "a = A()\n"
64 "for i = 1, 100000 do\n"
65 "test1(5, 4.6, 'foo', a)\n"
68 std::clock_t end1
= std::clock();
71 // benchmark empty binding
72 std::clock_t start2
= std::clock();
73 lua_dostring(L
, "a = A()\n"
74 "for i = 1, 100000 do\n"
75 "test2(5, 4.6, 'foo', a)\n"
78 std::clock_t end2
= std::clock();
79 total1
+= end1
- start1
;
80 total2
+= end2
- start2
;
84 double time1
= double(total1
) / (double)CLOCKS_PER_SEC
;
85 double time2
= double(total2
) / (double)CLOCKS_PER_SEC
;
87 #ifdef LUABIND_NO_ERROR_CHECKING
88 std::cout
<< "without error-checking\n";
90 std::cout
<< "luabind:\t" << time1
* 1000000 / num_calls
/ loops
<< " microseconds per call\n"
91 << "empty:\t" << time2
* 1000000 / num_calls
/ loops
<< " microseconds per call\n"
92 << "diff:\t" << ((time1
- time2
) * 1000000 / num_calls
/ loops
) << " microseconds\n\n";