Add performance measurements to README

This commit is contained in:
James Roseborough
2010-08-15 03:56:03 +00:00
parent c577f5debc
commit f21610e00a
4 changed files with 215 additions and 0 deletions

View File

@@ -72,6 +72,56 @@ at improving on the 1.0 vm in the following aspects.
<li>Improved weak table support, including weak keys.
</ul>
<h2>Performance</h2>
Good performance is a major goal of luaj.
The following table provides measured execution times on a subset of benchmarks from
<a href="http://shootout.alioth.debian.org/">the computer language benchmarks game</a>
in comparison with the standard C distribution.
<table cellspacing="10"><tr><td><table>
<tr valign="top">
<td><u>Language</td>
<td><u>Project</td>
<td><u>Version</td>
<td rowspan="6">&nbsp;&nbsp;</td>
<td colspan="4" align="center"><u>Execution&nbsp;time&nbsp;(sec)</td>
<td rowspan="6">&nbsp;&nbsp;</td>
<td><u>Sample&nbsp;command</td>
</tr>
<tr valign="top"><td colspan="3"></td>
<td><em>binarytrees 15</em></td>
<td><em>nsieve 9</em></td>
<td><em>fannkuch 10</em></td>
<td><em>nbody 1e6</em></td>
</tr>
<tr valign="top"><td>C</td><td>lua</td><td>5.1.4</td>
<td>17.637</td>
<td>5.477</td>
<td>16.044</td>
<td>15.201</td>
<td>lua fannkuch.lua 10</td></tr>
<tr valign="top"><td rowspan="3">Java</td><td>luaj (interpreted)</td><td>2.0</td>
<td>18.355</td>
<td>18.339</td>
<td>33.953</td>
<td>48.088</td>
<td>java -cp luaj-jse-2.0.jar lua fannkuch.lua 10</td></tr>
<tr valign="top"><td>luaj -j (lua2java)</td><td>2.0</td>
<td>4.463</td>
<td>13.789</td>
<td>5.884</td>
<td>16.701</td>
<td>java -cp luaj-jse-2.0.jar lua <b>-j</b> fannkuch.lua 10</td></tr>
<tr valign="top"><td>luaj -b (luajc)</td><td>2.0</td>
<td>2.980</td>
<td>11.274</td>
<td>5.073</td>
<td>16.794</td>
<td>java -cp luaj-jse-2.0.jar;bcel-5.2.jar lua <b>-b</b> fannkuch.lua 10</td></tr>
</table></td></tr></table>
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 <em>faster</em> than
C-based lua in some cases.
<h1>2 - <a name="2">Simple Examples</a></h1>
<h2>Run a lua script in Java SE</h2>
@@ -118,6 +168,12 @@ The output <em>hello.java</em> is Java source, that implements the logic in hell
Once <em>hello.java</em> is compiled into <em>hello.class</em> 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.
<p>
Lua scripts can also be run directly in this mode without precompiling using the <em>lua</em> command with the <b><em>-j</em></b> option when run in JDK 1.5 or higher:
<pre>
java -cp lib/luaj-jse-2.0.jar lua -j examples/lua/hello.lua
</pre>
<h2>Compile lua bytecode to java bytecode</h2>
<p>
@@ -134,9 +190,13 @@ The output <em>hello.class</em> 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).
<p>
Lua scripts can also be run directly in this mode without precompiling using the <em>lua</em> command with the <b><em>-b</em></b> option and providing the <em>bcel</em> library in the class path:
<pre>
java -cp &quot;lib/luaj-jse-2.0.jar;lib/bcel-5.2.jar&quot; lua -b examples/lua/hello.lua
</pre>
<h2>Run a script in a Java Application</h2>
<p>

70
build-perf.xml Normal file
View File

@@ -0,0 +1,70 @@
<project default="all">
<import file="build.xml"/>
<available file="luaj-jse-2.0.jar" property="luaj2.lib.exists"/>
<available file="lib/jill-1.0.1.jar" property="jill.lib.exists"/>
<available file="lib/kahlua.jar" property="kahlua.lib.exists"/>
<available file="lib/mochalua-1.0.jar" property="mochalua.lib.exists"/>
<target name="luaj2-lib" unless="luaj2.lib.exists">
<antcall target="jar-jse"/>
</target>
<target name="jill-lib" unless="jill.lib.exists">
<mkdir dir="lib"/>
<get src="http://jillcode.googlecode.com/files/jill-1.0.1.zip"
dest="lib/jill-1.0.1.zip"/>
<unzip src="lib/jill-1.0.1.zip" dest="lib" overwrite="true"/>
<ant dir="lib/jill-1.0.1" target="compile"/>
<jar destfile="lib/jill-1.0.1.jar" basedir="lib/jill-1.0.1/compiled"/>
</target>
<target name="kahlua-lib" unless="kahlua.lib.exists">
<get src="http://kahlua.googlecode.com/files/kahlua.jar"
dest="lib/kahlua.jar"/>
</target>
<target name="mochalua-lib" unless="mochalua.lib.exists">
<get src="http://mochalua.googlecode.com/files/Mochalua%201.0.jar"
dest="lib/mochalua-1.0.jar"/>
</target>
<target name="perf-libs" depends="luaj1-lib,luaj2-lib,bcel-lib,jill-lib,kahlua-lib,mochalua-lib"/>
<macrodef name="perftest">
<attribute name="program" default="lua"/>
<attribute name="luaprog" default="fannkuch.lua 10"/>
<attribute name="basedir" default="test/lua/perf/"/>
<sequential>
<echo level="info">------ @{program} @{luaprog}</echo>
<exec executable="bash">
<arg value="-c"/>
<arg value="time @{program} @{basedir}@{luaprog}"/>
</exec>
</sequential>
</macrodef>
<macrodef name="testcase">
<attribute name="luaprog" default="fannkuch.lua 10"/>
<sequential>
<echo level="info">=========== @{luaprog} =============</echo>
<perftest program="java -version" luaprog="" basedir=""/>
<perftest program="lua" luaprog="@{luaprog}"/>
<!-- <perftest program="java -cp lib/luaj-j2se-1.0.4.jar lua" luaprog="@{luaprog}"/> -->
<perftest program="java -cp luaj-jse-2.0.jar lua" luaprog="@{luaprog}"/>
<perftest program="java -cp luaj-jse-2.0.jar lua -j" luaprog="@{luaprog}"/>
<perftest program="java -cp luaj-jse-2.0.jar\\;lib/bcel-5.2.jar lua -b" luaprog="@{luaprog}"/>
</sequential>
</macrodef>
<target name="alltests">
<testcase luaprog="binarytrees.lua 15"/>
<testcase luaprog="nsieve.lua 9"/>
<testcase luaprog="fannkuch.lua 10"/>
<testcase luaprog="nbody.lua 1000000"/>
</target>
<target name="all" depends="alltests"/>
</project>

View File

@@ -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)))

35
test/lua/perf/nsieve.lua Normal file
View File

@@ -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)))