Add pretty-printing to the performance test suite.

This commit is contained in:
ActivexDiamond 2023-03-05 19:42:39 +03:00
parent aa8f88b317
commit 90c435c9c1
2 changed files with 13 additions and 9 deletions

View File

@ -2,13 +2,17 @@ local class = require 'middleclass'
time = require 'performance/time' time = require 'performance/time'
time('class creation', function() print("|---------------------------------------------------|")
print("| process | ms |")
print("|---------------------------------------------------|")
time('class creation ', function()
local A = class('A') local A = class('A')
end) end)
local A = class('A') local A = class('A')
time('instance creation', function() time('instance creation ', function()
local a = A:new() local a = A:new()
end) end)
@ -18,7 +22,7 @@ end
local a = A:new() local a = A:new()
time('instance method invocation', function() time('instance method invocation ', function()
a:foo() a:foo()
end) end)
@ -26,7 +30,7 @@ local B = class('B', A)
local b = B:new() local b = B:new()
time('inherited method invocation', function() time('inherited method invocation ', function()
b:foo() b:foo()
end) end)
@ -34,10 +38,12 @@ function A.static:bar()
return 2 return 2
end end
time('class method invocation', function() time('class method invocation ', function()
A:bar() A:bar()
end) end)
time('inherited class method invocation', function() time('inherited class method invocation', function()
B:bar() B:bar()
end) end)
print("|---------------------------------------------------|")

View File

@ -1,5 +1,4 @@
return function(title, f) return function(title, f)
collectgarbage() collectgarbage()
local startTime = os.clock() local startTime = os.clock()
@ -7,7 +6,6 @@ return function(title, f)
for i=0,10000 do f() end for i=0,10000 do f() end
local endTime = os.clock() local endTime = os.clock()
print( title, endTime - startTime ) print(string.format("| %s | %13.9f |", title, (endTime - startTime) * 1e3))
end end