lua-users home
lua-l archive

Re: LuaJIT string concat

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


On 14/04/2011, at 8:59 AM, Pierre-Yves Gérardy wrote:
> Here you are:
> 
> local sformat, rnd, tostring, a =
> string.format, math.random, tostring, nil
> for i= 1,10000000 do
> a = sformat( "[%s]", tostring(rnd()) )
> -- a = "["..tostring(rnd).."]"
> end
> 
> As I told you earlier, I removed table.concat from the benchmark since
> it was a constant factor, likely to dominate the benchmark
Why not profile it? (you'll need to look at the output in a monospaced font)
$ lua -luatrace.profile concat-bench.lua 
...
==================================================================================
Visits Total Self Child Line | concat-bench.lua - Times in milliseconds
----------------------------------------------------------------------------------
 1 0.00 0.00 0.00 1 | local t = {}
 101 0.01 0.01 0.00 2 | for i = 1, 100 do
 100 0.25 0.25 0.00 3 | t[i] = "abc"..tostring(i)
 . . . . 4 | end
 . . . . 5 | 
 . . . . 6 | local sformat, rnd, tostring, a =
 1 0.00 0.00 0.00 7 | string.format, math.random, tostring, nil
 . . . . 8 | 
100001 9.28 9.28 0.00 9 | for i= 1,100000 do
100000 648.02 648.02 0.00 10 | local s = table.concat(t, ",")
100000 96.93 96.93 0.00 11 | a = sformat("[%s]", s)
 . . . . 12 | end
 . . . . 13 | 
100001 9.40 9.40 0.00 14 | for i= 1,100000 do
100000 644.82 644.82 0.00 15 | local s = table.concat(t, ",")
100000 60.55 60.55 0.00 16 | a = "["..s.."]"
 1 0.00 0.00 0.00 17 | end

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