lua-users home
lua-l archive

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


Hi, I implemented my very first C module for a lua program, be nice :-).

The code in question is a single function, subsequenceMatch. This
function checks whether a given subsequence [1] of chars can be found
in a string.

Example: the subsequence "abc" can be found in "abaco" but not in "abominable".

The function returns true if the subsequence is completely contained
in the string, or a number which points to the first char in the
subsequence that could not be found.

Without further ado:

https://gist.github.com/938457

There is a bench program and a test one in case you feel like meddling
with the code. Here are the results of the benchmarks in my machine:

 ▸ uname -a
Linux thousandsunny 2.6.37-ARCH #1 SMP PREEMPT Fri Mar 25 15:10:00 CET
2011 x86_64 Intel(R) Core(TM)2 Duo CPU T6400 @ 2.00GHz GenuineIntel
GNU/Linux

▸ lua -v
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
▸ lua ssbench.lua
lua 5.94
C ext 0.24

▸ luajit-2.0.0-beta6 -v
LuaJIT 2.0.0-beta6 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
▸ luajit-2.0.0-beta6 ssbench.lua
lua 1.36
C ext 0.17

I'm pretty happy with the 24x speed up for lua and 8x speed up for
luajit but since I'm running the function over thousands of strings
I'm wondering if a little more speed could be squeezed on the C side.

Thanks in advance!

1: http://en.wikipedia.org/wiki/Subsequence

--------------------------------------------------------------
EmmanuelOga.com - Software Developer