lua-users home
lua-l archive

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


First try (lua cli)
double  223750
long    220468
single  226838

Second try (lua cli)
double  223459
long    226024
single  229658

Third try (lua test.lua)
double  230783
long    226451
single  232939

Forth try (lua test.lua)
double  229398
long    225754
single  23042

I guess the test can done other way, perhaps generating 5000 aleatory lines of string for every case and measure which is parsed faster.

Blessings!


On Mon, Oct 12, 2009 at 8:32 AM, Ico <lua@zevv.nl> wrote:

> In most languages (not only scripting) the use of single quotes is faster
> than double quotes, does it is applicable in Lua? perhaps for the other ways
> define strings?

When in doubt, just test.

code = {
 double = [[ a = "test 1234\n" ]],
 single = [[ a = 'test 1234\n' ]],
 long   = [=[ a = [[test 1234\n]] ]=]
}

for type, line in pairs(code) do
       t1 = os.time()
       while t1 == os.time() do end
       t1 = t1 + 1
       count = 0
       while t1 == os.time() do
               chunk = loadstring(line)
               chunk()
               count = count + 1
       end
       print(type, count)
end

(bad example because of the os.time() overhead in each loop, but sure to
complete in a few seconds)

Result on my intel 2.2Ghz show no sigificant difference:

double  257167
long    251103
single  254788


--
:wq
^X^Cy^K^X^C^C^C^C



--
Fernando P. García, http://www.develcuy.com
Developer - Analista de Sistemas
+51 1 9 8991 7871, Calle Santa Catalina Ancha #377, Cusco -Perú

** Antes de imprimir este mensaje piensa en tu compromiso con el medio ambiente, protegerlo depende de tí.