lua-users home
lua-l archive

Re: LuaJIT string concat

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


On 4/13/11 11:28 PM, Geoff Leyland wrote: [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

Hi Geoff,

great profiler module. I am seeing an even more pronounced difference ...


File:line Visits Total Self Child | Line
test/concat-bench.lua:5 1 0.01 0.01 0.00 | local t = {}
test/concat-bench.lua:7 101 0.31 0.31 0.00 | for i = 1, 100 do
test/concat-bench.lua:8 100 1.39 1.39 0.00 | t[i] = "abc"..tostring(i)
test/concat-bench.lua:12 1 0.00 0.00 0.00 | string.format, math.random, tostring, nil
test/concat-bench.lua:14 100001 295.24 295.24 0.00 | for i= 1,100000 do
test/concat-bench.lua:15 100000 2036.54 2036.54 0.00 | local s = table.concat(t, ",")
test/concat-bench.lua:16 100000 1048.60 1048.60 0.00 | a = sformat("[%s]", s)
test/concat-bench.lua:19 100001 292.81 292.81 0.00 | for i= 1,100000 do
test/concat-bench.lua:20 100000 2034.15 2034.15 0.00 | local s = table.concat(t, ",")
test/concat-bench.lua:21 100000 372.85 372.85 0.00 | a = "["..s.."]"
test/concat-bench.lua:22 1 0.00 0.00 0.00 | end

You tested that on a mac, too?

Henning

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