added performance tests

This commit is contained in:
Enrique García Cota 2011-09-18 16:42:57 +02:00
parent 1df9ccf178
commit 2271813323
2 changed files with 56 additions and 0 deletions

43
performance/run.lua Normal file
View File

@ -0,0 +1,43 @@
require 'middleclass'
time = require 'performance/time'
time('class creation', function()
local A = class('A')
end)
local A = class('A')
time('instance creation', function()
local a = A:new()
end)
function A:foo()
return 1
end
local a = A:new()
time('instance method invocation', function()
a:foo()
end)
local B = class('B', A)
local b = B:new()
time('inherited method invocation', function()
b:foo()
end)
function A.static:bar()
return 2
end
time('class method invocation', function()
A:bar()
end)
time('inherited class method invocation', function()
B:bar()
end)

13
performance/time.lua Normal file
View File

@ -0,0 +1,13 @@
return function(title, f)
collectgarbage()
local startTime = os.clock()
for i=0,10000 do f() end
local endTime = os.clock()
print( title, endTime - startTime )
end