View Single Post
03-09-12, 01:22 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,335
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:
  1. local function func1()
  2. --  Put Function 1 code here
  3.     return ("a !teST message"):find("![tT][eE][sS][tT]");
  4. end
  5.  
  6. local function func2()
  7. --  Put Function 2 code here
  8.     return ("a !teST message"):lower():find("!test");
  9. end
  10.  
  11. --  These are run a lot, need local pointers
  12. local math,debugprofilestart,debugprofilestop=math,debugprofilestart,debugprofilestop;
  13. SlashCmdList.FUNCTEST=function()
  14.     local l1,l2,h1,h2;
  15.     local s1,s2,c1,c2=0,0,0,0;
  16.     for i=1,1000000 do
  17.         local t1,t2;
  18.  
  19. --      Mix up the order these functions are run (Sometimes this affects run times)
  20.         if i%2>0 then
  21.             debugprofilestart(); func1(); t1=debugprofilestop();
  22.             debugprofilestart(); func2(); t2=debugprofilestop();
  23.         else
  24.             debugprofilestart(); func2(); t2=debugprofilestop();
  25.             debugprofilestart(); func1(); t1=debugprofilestop();
  26.         end
  27.  
  28. --      Add to total times
  29.         s1=s1+t1;
  30.         s2=s2+t2;
  31.  
  32. --      Compare which ran the shortest and increment relevant "Best" count
  33. --      Note: Times can be equal, in which ignore and calculate "Equal" count later
  34.         if t1<t2 then
  35.             c1=c1+1;
  36.         elseif t1>t2 then
  37.             c2=c2+1;
  38.         end
  39.  
  40. --      Set/Update min/max vars
  41.         if not l1 then
  42.             l1,h1,l2,h2=t1,t1,t2,t2;
  43.         else
  44.             l1=math.min(l1,t1);
  45.             l2=math.min(l2,t2);
  46.             h1=math.max(h1,t1);
  47.             h2=math.max(h2,t2);
  48.         end
  49.     end
  50.  
  51. --  Print results
  52.     print("Totals",s1,s2);
  53.     print("Avg",s1/1000000,s2/1000000);
  54.     print("High",h1,h2);
  55.     print("Low",l1,l2);
  56.     print("Best",c1,c2);
  57.     print("Equal",1000000-c1-c2);
  58. end;
  59.  
  60. SLASH_FUNCTEST1="/functest";
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote