mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
added performance tests
This commit is contained in:
parent
b424317c9d
commit
151872d4ba
@ -3,5 +3,41 @@ require 'middleclass'
|
||||
time = require 'performance/time'
|
||||
|
||||
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)
|
||||
|
@ -1,9 +1,13 @@
|
||||
return function(title, f)
|
||||
|
||||
local start = os.clock()
|
||||
collectgarbage()
|
||||
|
||||
local startTime = os.clock()
|
||||
|
||||
for i=0,10000 do f() end
|
||||
|
||||
print( title, os.clock() - start )
|
||||
local endTime = os.clock()
|
||||
|
||||
print( title, endTime - startTime )
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user