diff --git a/README.html b/README.html index 76f2b526..80a58bc7 100644 --- a/README.html +++ b/README.html @@ -72,6 +72,56 @@ at improving on the 1.0 vm in the following aspects.
  • Improved weak table support, including weak keys. +

    Performance

    +Good performance is a major goal of luaj. +The following table provides measured execution times on a subset of benchmarks from +the computer language benchmarks game +in comparison with the standard C distribution. +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    LanguageProjectVersion  Execution time (sec)  Sample command
    binarytrees 15nsieve 9fannkuch 10nbody 1e6
    Clua5.1.417.6375.47716.04415.201lua fannkuch.lua 10
    Javaluaj (interpreted)2.018.35518.33933.95348.088java -cp luaj-jse-2.0.jar lua fannkuch.lua 10
    luaj -j (lua2java)2.04.46313.7895.88416.701java -cp luaj-jse-2.0.jar lua -j fannkuch.lua 10
    luaj -b (luajc)2.02.98011.2745.07316.794java -cp luaj-jse-2.0.jar;bcel-5.2.jar lua -b fannkuch.lua 10
    +Luaj in interpreted mode performs well for the benchmarks, and even better when source-to-source (lua2java) +or bytecode-to-bytecode (luajc) compilers are used, and actually executes faster than +C-based lua in some cases. +

    2 - Simple Examples

    Run a lua script in Java SE

    @@ -118,6 +168,12 @@ The output hello.java is Java source, that implements the logic in hell Once hello.java is compiled into hello.class it can be required and used in place of the original lua script, but with better performance. There are no additional dependencies for compiling or running source-to-source compiled lua. +

    +Lua scripts can also be run directly in this mode without precompiling using the lua command with the -j option when run in JDK 1.5 or higher: +

    +	java -cp lib/luaj-jse-2.0.jar lua -j examples/lua/hello.lua
    +
    +

    Compile lua bytecode to java bytecode

    @@ -134,9 +190,13 @@ The output hello.class is Java bytecode, should run and produce the sam There is no runtime dependency on the bcel library, but the compiled classes must be in the class path at runtime, unless runtime jit-compiling via luajc and bcel are desired (see later sections). +

    +Lua scripts can also be run directly in this mode without precompiling using the lua command with the -b option and providing the bcel library in the class path:

    +	java -cp "lib/luaj-jse-2.0.jar;lib/bcel-5.2.jar" lua -b examples/lua/hello.lua
     
    +

    Run a script in a Java Application

    diff --git a/build-perf.xml b/build-perf.xml new file mode 100644 index 00000000..f28ab919 --- /dev/null +++ b/build-perf.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ------ @{program} @{luaprog} + + + + + + + + + + + + =========== @{luaprog} ============= + + + + + + + + + + + + + + + + + + diff --git a/test/lua/perf/binarytrees.lua b/test/lua/perf/binarytrees.lua new file mode 100644 index 00000000..04ca7eee --- /dev/null +++ b/test/lua/perf/binarytrees.lua @@ -0,0 +1,50 @@ +-- The Computer Language Benchmarks Game +-- http://shootout.alioth.debian.org/ +-- contributed by Mike Pall + +local function BottomUpTree(item, depth) + if depth > 0 then + local i = item + item + depth = depth - 1 + local left, right = BottomUpTree(i-1, depth), BottomUpTree(i, depth) + return { item, left, right } + else + return { item } + end +end + +local function ItemCheck(tree) + if tree[2] then + return tree[1] + ItemCheck(tree[2]) - ItemCheck(tree[3]) + else + return tree[1] + end +end + +local N = tonumber(arg and arg[1]) or 0 +local mindepth = 4 +local maxdepth = mindepth + 2 +if maxdepth < N then maxdepth = N end + +do + local stretchdepth = maxdepth + 1 + local stretchtree = BottomUpTree(0, stretchdepth) + io.write(string.format("stretch tree of depth %d\t check: %d\n", + stretchdepth, ItemCheck(stretchtree))) +end + +local longlivedtree = BottomUpTree(0, maxdepth) + +for depth=mindepth,maxdepth,2 do + local iterations = 2 ^ (maxdepth - depth + mindepth) + local check = 0 + for i=1,iterations do + check = check + ItemCheck(BottomUpTree(1, depth)) + + ItemCheck(BottomUpTree(-1, depth)) + end + io.write(string.format("%d\t trees of depth %d\t check: %d\n", + iterations*2, depth, check)) +end + +io.write(string.format("long lived tree of depth %d\t check: %d\n", + maxdepth, ItemCheck(longlivedtree))) diff --git a/test/lua/perf/nsieve.lua b/test/lua/perf/nsieve.lua new file mode 100644 index 00000000..475a05b4 --- /dev/null +++ b/test/lua/perf/nsieve.lua @@ -0,0 +1,35 @@ +-- The Computer Language Shootout +-- http://shootout.alioth.debian.org/ +-- contributed by Isaac Gouy +-- modified by Mike Pall + + +local function nsieve(m,isPrime) + for i=2,m do + isPrime[i] = true + end + local count = 0 + + for i=2,m do + if isPrime[i] then + for k=i+i, m, i do + if isPrime[k] then isPrime[k] = false end + end + count = count + 1 + end + end + return count +end + + +local n = tonumber(arg and arg[1]) or 1 +local flags = {} + +local m = (2^n)*10000 +print( string.format("Primes up to %8d %8d", m, nsieve(m,flags))) + +m = (2^(n-1))*10000 +print( string.format("Primes up to %8d %8d", m, nsieve(m,flags))) + +m = (2^(n-2))*10000 +print( string.format("Primes up to %8d %8d", m, nsieve(m,flags)))