Last active
February 20, 2016 23:52
-
-
Save TerryE/a511bd0b05d4a77c3f9c to your computer and use it in GitHub Desktop.
benchmark.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function benchmark(count1,count2,opt) | |
local workLoop,fn = [[ | |
local x,clr,n = "",tmr.wdclr,...; | |
for i = 1, n,1 do x = x .. "."; if n%100 == 0 then clr() end end; | |
return x:len() | |
]] | |
file.open("test.lua","w"); file.writeline(workLoop); file.close() | |
if opt == 1 then | |
fn = loadstring(workLoop) | |
elseif opt == 2 then | |
fn = function(n) return loadfile("test.lua")(n) end | |
else -- opt==3 | |
node.compile("test.lua") | |
fn = function(n) return loadfile("test.lc")(n) end | |
end | |
workLoop=nil | |
local tott,totn = 0,0 | |
for i = 1,count1,1 do | |
-- collectgarbage(); | |
local t, n = tmr.now(), fn(count2) | |
tmr.wdclr() | |
tott = tott + tmr.now()-t | |
totn = totn + n | |
end | |
print(('%8.3f mSec, check = %d, heap = %d'):format(tott/1000,totn, node.heap())) | |
file.remove("test.lua"); | |
file.remove("test.lc"); | |
for i=1,3 do collectgarbage() print(node.heap()) end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment