LUA字符串分割方法性能比较
来源:互联网 发布:24u网络机柜 编辑:程序博客网 时间:2024/05/18 09:09
function lua_string_split(s, p)
local rt = {}
string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
return rt
end
function split(str,splitor)
if(splitor==nil) then
splitor=","
end
local strArray={}
local strStart=1
--print(str)
--print(splitor);
local splitorLen = string.len(splitor)
--print(splitor);([^,]+)
local index=string.find(str,splitor,strStart)
if(index==nil) then
strArray[1]=str
return strArray
end
local i=1
while index do
strArray[i]=string.sub(str,strStart,index-1)
i=i+1
strStart=index+splitorLen
index = string.find(str,splitor,strStart)
end
strArray[i]=string.sub(str,strStart,string.len(str))
return strArray
end
function checklaj()
e = os.clock()
for i=100000,1,-1 do
local b = split("aa|bb|cc|ee|ff|gg|ii","|")
end
f = os.clock()
print(f-e) --1.528293
end
function checktimer()
a = os.clock()
for i=100000,1,-1 do
local b = lua_string_split("aa|bb|cc|ee|ff|gg|ii","|")
end
c = os.clock()
print(c-a) --1.528293
end
--checktimer();
checklaj();
local rt = {}
string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
return rt
end
function split(str,splitor)
if(splitor==nil) then
splitor=","
end
local strArray={}
local strStart=1
--print(str)
--print(splitor);
local splitorLen = string.len(splitor)
--print(splitor);([^,]+)
local index=string.find(str,splitor,strStart)
if(index==nil) then
strArray[1]=str
return strArray
end
local i=1
while index do
strArray[i]=string.sub(str,strStart,index-1)
i=i+1
strStart=index+splitorLen
index = string.find(str,splitor,strStart)
end
strArray[i]=string.sub(str,strStart,string.len(str))
return strArray
end
function checklaj()
e = os.clock()
for i=100000,1,-1 do
local b = split("aa|bb|cc|ee|ff|gg|ii","|")
end
f = os.clock()
print(f-e) --1.528293
end
function checktimer()
a = os.clock()
for i=100000,1,-1 do
local b = lua_string_split("aa|bb|cc|ee|ff|gg|ii","|")
end
c = os.clock()
print(c-a) --1.528293
end
--checktimer();
checklaj();
checktimer();
这个运行时间 有时候代码挤一挤 速度就起来了
0.346
0.292
0 0
- LUA字符串分割方法性能比较
- java字符串分割性能比较
- java字符串分割性能比较
- 字符串分割方式和查找方法比较
- lua字符串分割函数
- lua 字符串分割函数
- [Lua] 字符串分割
- lua string 分割字符串
- lua字符串分割
- lua 分割字符串
- lua字符串分割
- Lua 分割字符串
- lua 分割字符串
- String类的split()方法与StringTokenizer方法对字符串分割并输出内容的性能比较
- Lua的字符串分割函数
- Lua string split分割字符串
- Lua的字符串分割函数
- lua字符串的分割函数
- ice版本resize 错误调试(Host key verification failed)
- SQL查询表中重复记录
- ANDROID 解析json数据
- ios 中生成随机数
- 网易新闻iOS版使用的开源组件
- LUA字符串分割方法性能比较
- delphii快速获取网页源码方法
- 理解php Hash函数,增强密码安全
- 将opencv1.0安装到Linux
- Cordys 对 LDAP的 操作 【增加、删除、修改】
- 操作系统--6设备管理
- 设计模式初体验---策略模式Strategy
- 欢迎使用CSDN-markdown编辑器
- SQL建立相同的表导数据