On Wed, Mar 12, 2008 at 03:57:59AM +0900, William James wrote:
> Ruby's gsub is far too slow.  7stud even beat it with an each_byte
> loop!
> Disgraceful.  Disgusting.  Inexcusable.
> 
> The Lua code:
> 
> s = string.rep( 'abc', 1000000 )
> 
> time = os.clock()
> string.gsub( s, '(.)', "%1%1" )
> print( os.clock() - time, "seconds" )

I don't think your code is doing what you think it is doing:

[pbrannan@zaphod tmp]$ cat test.lua
-- s = string.rep( 'abc', 100000 )
s = 'abcabcabc'

time = os.clock()
string.gsub( s, '(.)', "%1%1" )
print(s)
print( os.clock() - time, "seconds" )

[pbrannan@zaphod tmp]$ lua test.lua
abcabcabc
0       seconds
[pbrannan@zaphod tmp]$ lua -v
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio

Paul