I don't have time to run it at the moment, but here's a modified version of a comparison function I used in another thread. If nobody replies with the printed results, I'll run it later tonight.
lua Code:
local function func1()
-- Put Function 1 code here
return ("a !teST message"):find("![tT][eE][sS][tT]");
end
local function func2()
-- Put Function 2 code here
return ("a !teST message"):lower():find("!test");
end
-- These are run a lot, need local pointers
local math,debugprofilestart,debugprofilestop=math,debugprofilestart,debugprofilestop;
SlashCmdList.FUNCTEST=function()
local l1,l2,h1,h2;
local s1,s2,c1,c2=0,0,0,0;
for i=1,1000000 do
local t1,t2;
-- Mix up the order these functions are run (Sometimes this affects run times)
if i%2>0 then
debugprofilestart(); func1(); t1=debugprofilestop();
debugprofilestart(); func2(); t2=debugprofilestop();
else
debugprofilestart(); func2(); t2=debugprofilestop();
debugprofilestart(); func1(); t1=debugprofilestop();
end
-- Add to total times
s1=s1+t1;
s2=s2+t2;
-- Compare which ran the shortest and increment relevant "Best" count
-- Note: Times can be equal, in which ignore and calculate "Equal" count later
if t1<t2 then
c1=c1+1;
elseif t1>t2 then
c2=c2+1;
end
-- Set/Update min/max vars
if not l1 then
l1,h1,l2,h2=t1,t1,t2,t2;
else
l1=math.min(l1,t1);
l2=math.min(l2,t2);
h1=math.max(h1,t1);
h2=math.max(h2,t2);
end
end
-- Print results
print("Totals",s1,s2);
print("Avg",s1/1000000,s2/1000000);
print("High",h1,h2);
print("Low",l1,l2);
print("Best",c1,c2);
print("Equal",1000000-c1-c2);
end;
SLASH_FUNCTEST1="/functest";