My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Speed_comparisons  

Featured
Updated Jun 5, 2010 by liamdev...@gmail.com

OOLua Binding Framework speed compared to other bindings.

Introduction

For these profile tests the following libraries were used:

  • Luabind 0.9.0 (Using the defines LUABIND_NO_ERROR_CHECKING and LUABIND_DONT_COPY_STRINGS) and Boost 1.4.0
  • OOLua 1.3 Using defines OOLUA_RUNTIME_CHECKS_ENABLED == 1 OOLUA_SAFE_ID_COMPARE == 1
  • Times also shown when using OOLUA_RUNTIME_CHECKS_ENABLED == 0
  • Swig 1.3.40

Setting and getting

Getting 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

Note: this code differs slightly in the construction of class instances for each framework see (library name)set_and_get.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.35884560.3289822
Luabind0.6606246
Swig0.8161317

Class exchanging

The 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 base

Lua code

Note: this code differs slightly in the construction of class instances for each framework see (library name)derived.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.37510270.2739998
Swig0.3823656
Luabind0.4523089

Passing a derived class which uses multiple inheritance in Lua to a C++ member class that wants a base

Lua code

Note: this code differs slightly in the construction of class instances for each framework see (library name)derived.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.39288640.3188173
Swig0.4145844
Luabind0.4654789

The following test should give the same results per library, yet I wanted to check this.

Calling a virtual function

Lua code

Note: this code differs slightly in the construction of class instances for each framework see (library name)derived.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.16067610.1412019
Swig0.3456166
Luabind0.3162266

Calling a pure virtual function

Lua code

Note: this code differs slightly in the construction of class instances for each framework see (library name)derived.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.16362980.1382053
Swig0.3572994
Luabind0.3188037

Calling a pure virtual function on an instance passed to Lua

Lua code

Note: this code differs slightly in the construction of class instances for each framework see (library name)derived.lua in the profile directory; yet the construction is not part of the profile test.

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

Library Time(sec) OOLua no runtime checks
OOLua0.1533290.137955
Luabind0.303186
Swig0.40603

Comment by Linker.M...@gmail.com, Dec 5, 2009

OOLua is very fast! :)


Sign in to add a comment
Powered by Google Project Hosting