lua-users home
lua-l archive

Re: precompiled regex's to lua

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


Roberto Ierusalimschy wrote:
When sending results, it is quite useful to know results of what. Could
you send the source of these tests?
For what it worth :)
-- A simple test with synthesized CSV:
local pcre = require "rex_pcre"
local rep, gmatch = string.rep, (string.gmatch or string.gfind)
local subj = rep (rep ("abcd", 100) .. ",", 100) .. "a"
local num = assert (tonumber (arg[1]))
--> 700 uSec/iteration (Lrexlib PCRE binding)
if arg[2] == "pcre" then
 local r = pcre.new ("[^,]+\,円?") -- precompiling regex
 for i = 1, num do
 r:gmatch (subj, function(m, t) end)
 end
end
--> 1500 uSec/iteration (Lua 5.0)
--> 2200 uSec/iteration (Lua 5.1)
if arg[2] == "lua" then
 for i = 1, num do
 for c in gmatch (subj, "[^,]+%,?") do end
 end
end
--
Shmuel

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