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
1df9ccf178
commit
2271813323
43
performance/run.lua
Normal file
43
performance/run.lua
Normal 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
13
performance/time.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user