From 90c435c9c1ff5a38ffc75c7158732b20a4622fe7 Mon Sep 17 00:00:00 2001 From: ActivexDiamond Date: Sun, 5 Mar 2023 19:42:39 +0300 Subject: [PATCH] Add pretty-printing to the performance test suite. --- performance/run.lua | 16 +++++++++++----- performance/time.lua | 6 ++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/performance/run.lua b/performance/run.lua index 8d8ba47..340864b 100644 --- a/performance/run.lua +++ b/performance/run.lua @@ -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("|---------------------------------------------------|") diff --git a/performance/time.lua b/performance/time.lua index dd02455..3c0ec90 100644 --- a/performance/time.lua +++ b/performance/time.lua @@ -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