You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/03 02:50:18 UTC
[GitHub] [apisix] tokers commented on issue #2930: optimization: string concatenation in sls-logger.lua
tokers commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737628759
> Please give some performance testing to prove use string concatenation is not inefficient, I have do the performance test for sls log ,can not find any inefficient issue.
This is a classical bad practice for string concatenation. Just see the following snippet to benchmark it.
```lua
local function concat_100000x_way1(s)
local t = ""
for i = 1, 50000 do
t = t .. s
end
return t
end
local function concat_100000x_way2(s)
local t = {}
for i = 1, 50000 do
t[i] = s
end
return table.concat(t)
end
local function bench(func, s)
local s = os.time()
func(s)
print("cost time: ", os.time() - s)
end
bench(concat_100000x_way1, string.rep("haha", 50))
bench(concat_100000x_way2, string.rep("haha", 50))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org