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

View File

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