Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pretty-printing to the performance test suite. #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions performance/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -18,26 +22,28 @@ end

local a = A:new()

time('instance method invocation', function()
time('instance method invocation ', function()
a:foo()
end)

local B = class('B', A)

local b = B:new()

time('inherited method invocation', function()
time('inherited method invocation ', function()
b:foo()
end)

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("|---------------------------------------------------|")
6 changes: 2 additions & 4 deletions performance/time.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
return function(title, f)

collectgarbage()

local startTime = os.clock()

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