lua-users home
lua-l archive

Re: "String builder"-style optimization

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


thx Charles Heywood :)
-- benchMark(1000000, true, {func1, {params...}}, {func2, {params...}}, ...)
benchMark=function(turns, mem, ...)
 local res={}
 if mem then
 collectgarbage()
 collectgarbage('stop') end
 for i=1, select('#', ...) do
 local current=select(i, ...)
 local size
 if mem then
 collectgarbage()
 size=collectgarbage('count') end
 local time=os.time()
 for _=1, turns do
 current[1](current[2] and unpack(current[2])) end
 res[i]={os.difftime(os.time(), time), collectgarbage('count')-size} end
 if mem then collectgarbage('restart') end
 return res end

AltStyle によって変換されたページ (->オリジナル) /