|
Speed_comparisons
OOLua Binding Framework speed compared to other bindings.
IntroductionFor these profile tests the following libraries were used:
Times also shown when using OOLUA_RUNTIME_CHECKS_ENABLED == 0 Setting and gettingGetting and setting a member variable via a member function. C++ code class Set_get
{
public:
Set_get():_i(0.0){}
void set(double i)
{
_i = i;
}
double get()const
{
return _i;
}
private:
double _i;
};Lua code local N = 10
local ave = 0
local times = 1000000
for i = 0, N do
local obj = Set_get:new()
local t0 = os.clock()
for i=1,times do
obj:set(i)
if(obj:get() ~= i)then
error("failed")
end
end
local dt = os.clock()-t0
if i~=0 then
ave = ave + dt
end
end
print('OOLua access (average elapsed time):',ave/N)Access results
Class exchangingThe following tests use a class hierarchy as detailed below: class ProfileBase
{
public:
ProfileBase():_i(0){}
virtual ~ProfileBase(){}
void increment_a_base(ProfileBase* base)
{
++base->_i;
}
virtual void virtual_func()
{
++_i;
}
virtual void pure_virtual_func() = 0;
private:
int _i;
};
class ProfileAnotherBase
{
public:
virtual ~ProfileAnotherBase(){}
};
class ProfileDerived : public ProfileBase
{
public:
virtual ~ProfileDerived(){}
virtual void pure_virtual_func()
{
++_i;
}
private:
int _i;
};
class ProfileMultiBases : public ProfileDerived, public ProfileAnotherBase
{
public:
void virtual_func()
{
++_i;
}
private:
int _i;
};Passing a derived class in Lua to a C++ member class that wants a baseLua code local N = 10
local ave = 0
local times = 1000000
for i = 0, N do
local obj = ProfileDerived:new()
local increment_me = ProfileDerived:new()
local t0 = os.clock()
for i=1,times do
obj:increment_a_base(increment_me)
end
local dt = os.clock()-t0
if i~=0 then
ave = ave + dt
end
end
print('OOLua passing derived to a function that wants a base (average elapsed time):',ave/N)Wants base results
Passing a derived class which uses multiple inheritance in Lua to a C++ member class that wants a baseLua code local N = 10
local ave = 0
local times = 1000000
for i = 0, N do
local obj = ProfileDerived:new()
local increment_me = ProfileMultiBases:new()
local t0 = os.clock()
for i=1,times do
obj:increment_a_base(increment_me)
end
local dt = os.clock()-t0
if i~=0 then
ave = ave + dt
end
end
print('OOLua passing derived with multiple bases to a function that wants a base (average elapsed time):',ave/N)Multiple inheritance wants base results
The following test should give the same results per library, yet I wanted to check this. Calling a virtual functionLua code local N = 10
local ave = 0
local times = 1000000
for i = 0, N do
local obj = ProfileMultiBases:new()
local t0 = os.clock()
for i=1,times do
obj:virtual_func()
end
local dt = os.clock()-t0
if i~=0 then
ave = ave + dt
end
end
print('OOLua virtual function (average elapsed time):',ave/N)Calling a virtual function results
Calling a pure virtual functionLua code local N = 10
local ave = 0
local times = 1000000
for i = 0, N do
local obj = ProfileMultiBases:new()
local t0 = os.clock()
for i=1,times do
obj:pure_virtual_func()
end
local dt = os.clock()-t0
if i~=0 then
ave = ave + dt
end
end
print('OOLua pure virtual function (average elapsed time):',ave/N)Calling a pure virtual function results
Calling a pure virtual function on an instance passed to LuaLua code func = function(obj) local N = 10 local ave = 0 local times = 1000000 for i = 0, N do local t0 = os.clock() for i=1,times do obj:pure_virtual_func() end local dt = os.clock()-t0 if i~=0 then ave = ave + dt end end return ave/N end Calling a virtual function in a function results
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OOLua is very fast! :)