added performance tests

This commit is contained in:
Enrique García Cota 2011-09-09 18:48:33 +02:00
parent b424317c9d
commit 151872d4ba
2 changed files with 43 additions and 3 deletions

View File

@ -3,5 +3,41 @@ require 'middleclass'
time = require 'performance/time' time = require 'performance/time'
time('class creation', function() time('class creation', function()
local c = class('A') 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) end)

View File

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