lua-users home
lua-l archive

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


I've tested this bencmark sample, and test says that a bottleneck is string.gsub. So, I've replaced string.gsub with my simple realization of replace function in C.
Here modified code and results for first 5 steps:


    local str='abcdefgh'..'efghefgh';
    local imax=1024/#str*1024*4;         -- 4mb

    local starttime=os.time();
    print "exec.tm.sec\tstr.length";

    local gstr='';
    local i=0;

    while i < imax+1000 do
            i=i+1;
            gstr=gstr..str;
            gstr=string.swap(gstr,"efgh","____");
            local lngth=#str*i;
            if(math.mod(lngth,1024*256)==0) then
print(os.time()-starttime.."sec\t\t"..(lngth/1024).."kb");
            end
    end


Timings string.swap:
2sec        256kb
11sec        512kb
27sec        768kb
49sec        1024kb
78sec        1280kb

Timings string.gsub:
29sec        256kb
118sec        512kb
275sec        768kb

Tested on Intel Core i5-2300 2.8GHz