10 #define LUABIND_NO_ERROR_CHECKING
11 #define LUABIND_DONT_COPY_STRINGS
12 //#define LUABIND_NOT_THREADSAFE
14 #include <luabind/luabind.hpp>
25 float f1(int a
, float b
, const char* str
, A
* c
)
39 const int num_calls
= 1000000;
40 const int loops
= 100;
42 using namespace luabind
;
44 lua_State
* L
= lua_open();
47 .def(constructor
<>());
49 function(L
, "test1", &f1
);
51 lua_pushstring(L
, "test2");
52 lua_pushcclosure(L
, &f2
, 0);
53 lua_settable(L
, LUA_GLOBALSINDEX
);
55 std::clock_t total1
= 0;
56 std::clock_t total2
= 0;
58 for (int i
= 0; i
< loops
; ++i
)
61 std::clock_t start1
= std::clock();
62 lua_dostring(L
, "a = A()\n"
63 "for i = 1, 1000000 do\n"
64 "test1(5, 4.6, 'foo', a)\n"
67 std::clock_t end1
= std::clock();
70 // benchmark empty binding
71 std::clock_t start2
= std::clock();
72 lua_dostring(L
, "a = A()\n"
73 "for i = 1, 1000000 do\n"
74 "test2(5, 4.6, 'foo', a)\n"
77 std::clock_t end2
= std::clock();
78 total1
+= end1
- start1
;
79 total2
+= end2
- start2
;
83 double time1
= double(total1
) / (double)CLOCKS_PER_SEC
;
84 double time2
= double(total2
) / (double)CLOCKS_PER_SEC
;
86 #ifdef LUABIND_NO_ERROR_CHECKING
87 std::cout
<< "without error-checking\n";
89 #ifdef LUABIND_DONT_COPY_STRINGS
90 std::cout
<< "with constant strings\n";
92 std::cout
<< "luabind:\t" << time1
* 1000000 / num_calls
/ loops
<< " microseconds per call\n"
93 << "empty:\t" << time2
* 1000000 / num_calls
/ loops
<< " microseconds per call\n"
94 << "diff:\t" << ((time1
- time2
) * 1000000 / num_calls
/ loops
) << " microseconds\n\n";