-- regexdna_re2.lua re2 = require 'lua-re2' function printelapse(start) local elapse = os.clock() - start print(elapse..'s') end -- omitted code -- 'variants' is a table of regex dna patterns to match -- 'seq' is a *really* long dna sequence string loaded from stdin local start = os.clock() for i = 1, 10 do for _, p in ipairs(variants) do io.write( string.format('%s %d\n', p, re2(p):countmatch(seq)) ) end end printelapse(start) // lua-re2.cpp // a temporary function in my binding code used in the benchmark above static int re2_countmatch(lua_State *L) { lua_settop(L, 2); RE2 *re2obj = luaRE2_checkobject(L, 1); StringPiece subject( luaL_checkstring(L, 2) ); int c = 0; while(RE2::FindAndConsume(&subject, *re2obj)) ++c; lua_pushinteger(L, c); return 1; }
-- regexdna_re2.lua
re2 = require 'lua-re2'
function printelapse(start)
local elapse = os.clock() - start
print(elapse..'s')
end
-- omitted code -- 'variants' is a table of regex dna patterns to match -- 'seq' is a *really* long dna sequence string loaded from stdin
local start = os.clock()
for i = 1, 10 do
for _, p in ipairs(variants) do
io.write( string.format('%s %d\n', p, re2(p):countmatch(seq)) )
printelapse(start) // lua-re2.cpp // a temporary function in my binding code used in the benchmark above static int re2_countmatch(lua_State *L) { lua_settop(L, 2); RE2 *re2obj = luaRE2_checkobject(L, 1); StringPiece subject(
luaL_checkstring(L, 2)
); int c = 0; while(RE2::FindAndConsume(&subject, *re2obj)) ++c; lua_pushinteger(L, c); return 1; }
# regexdna.py from time import time from sys import stdin, stdout from re2 import sub, findall def printelapse(start): elapse = time() - start print(str(elapse) + 's') # omitted code start = time() for i in xrange(10): for f in variants: write(f.decode("utf-8") + ' ' + str(len(findall(f.decode("utf-8"), seq))) + '\n') printelapse(start)
# regexdna.py from time import time from sys import stdin, stdout
from re2 import sub, findall
def printelapse(start):
elapse = time() - start
print(str(elapse) + 's')
# omitted code
start = time()
for i in xrange(10):
for f in variants:
write(f.decode("utf-8") + ' ' + str(len(findall(f.decode("utf-8"), seq))) + '\n')
printelapse(start)
// regexdna.cpp #include "re2/re2.h" #include <iostream> #include <memory> #include <stdio.h> #include <time.h> int main(void) { // lots of omitted code clock_t start = clock(); for(int it = 0; it < 10; ++it) { for (int i = 0; i < (int)(sizeof(pattern1) / sizeof(string)); ++i) { int count = 0; RE2 pat(pattern1[i]); StringPiece piece = str; while (RE2::FindAndConsume(&piece, pat)) ++count; printf("%s %d\n", pattern1[i].c_str(), count); } } double elapse = (clock() - start)*1.0 / CLOCKS_PER_SEC; cout << elapse << "s\n"; }
// regexdna.cpp #include "re2/re2.h"
#include <iostream>
#include <memory>
#include <stdio.h>
#include <time.h>
int main(void)
{
// lots of omitted code
clock_t start = clock();
for(int it = 0; it < 10; ++it)
for (int i = 0; i < (int)(sizeof(pattern1) / sizeof(string)); ++i)
int count = 0;
RE2 pat(pattern1[i]);
StringPiece piece = str;
while (RE2::FindAndConsume(&piece, pat)) ++count;
printf("%s %d\n", pattern1[i].c_str(), count);
}
} double elapse = (clock() - start)*1.0 / CLOCKS_PER_SEC; cout << elapse << "s\n";
static int re2_countmatch(lua_State *L) { lua_settop(L, 2); RE2 *re2obj = luaRE2_checkobject(L, 1); static const string overhead_test = luaL_checkstring(L, 2); StringPiece subject( overhead_test ); int c = 0; while(RE2::FindAndConsume(&subject, *re2obj)) ++c; lua_pushinteger(L, c); return 1; }
static int re2_countmatch(lua_State *L)
lua_settop(L, 2);
RE2 *re2obj = luaRE2_checkobject(L, 1);
static const string overhead_test = luaL_checkstring(L, 2);
StringPiece subject( overhead_test );
int c = 0;
while(RE2::FindAndConsume(&subject, *re2obj))
++c;
lua_pushinteger(L, c);
return 1;
overhead_test
re2_countmatch
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル