Skip to content

Commit

Permalink
luvit is now 64bit, yajl benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kengonakajima committed Jan 9, 2012
1 parent 6db2ef4 commit 3592c08
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LUVITCONFIG=$(LUVIT) deps/luvit/bin/luvit-config.lua

ifeq ($(shell uname -sm | sed -e s,x86_64,i386,),Darwin i386)
#osx
export CC=gcc -arch i386
export CC=gcc #-arch i386
CFLAGS=$(shell luvit-config --cflags) -g -O3 -I./deps/luvit/deps/luajit/src
LIBS=$(shell luvit-config --libs) ./deps/luvit/deps/luajit/src/libluajit.a
LDFLAGS=
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ In your app:

Benchmark
====

command line:

luvit bench.lua

output:

mp: empty 0.69 sec 4347826.0869565 times/sec 6.5072463768116 times faster
mp: iary1 0.87 sec 3448275.862069 times/sec 5.9310344827586 times faster
mp: iary10 0.31 sec 967741.93548387 times/sec 2.9677419354839 times faster
Expand All @@ -42,6 +49,29 @@ Benchmark
mp: str1000 2.22 sec 1351351.3513514 times/sec 3.0855855855856 times faster
mp: str10000 1.76 sec 170454.54545455 times/sec 1.4545454545455 times faster

To compare with luvit's JSON (based on libyajl), command line:

luvit jsonbench.lua

output:

json: empty 0.304742 sec 98443.929619153 times/sec
json: iary1 0.402968 sec 74447.59881678 times/sec
json: iary10 0.060066 sec 49945.060433523 times/sec
json: iary100 0.031954 sec 9388.4959629468 times/sec
json: iary1000 0.302775 sec 990.83477830072 times/sec
json: iary10000 0.331131 sec 90.598584850105 times/sec
json: str1 0.244788 sec 122555.02720722 times/sec
json: str10 0.316844 sec 94683.81916653 times/sec
json: str100 0.420545 sec 71336.00447039 times/sec
json: str500 0.629439 sec 47661.489040241 times/sec
json: str1000 0.630663 sec 47568.986923286 times/sec
json: str10000 0.368189 sec 8147.9892120623 times/sec

lua-msgpack-native is 20x ~ 50x faster than luvit's JSON.



Related works
====
In many cases ,Lua runtime doesn't allow adding native modules.
Expand Down
2 changes: 1 addition & 1 deletion deps/luvit
Submodule luvit updated 90 files
+3 −0 .gitmodules
+202 −0 LICENSE.txt
+30 −13 Makefile
+4 −0 NOTICE.txt
+20 −0 bin/luvit-config.lua
+3 −2 common.gypi
+40 −0 deps/Makefile.yajl
+1 −1 deps/http-parser
+16 −18 deps/luajit.gyp
+1 −1 deps/uv
+1 −0 deps/yajl
+68 −0 deps/yajl.gyp
+24 −0 examples/json.lua
+8 −5 examples/tcp-echo-client.lua
+10 −9 examples/tcp-echo-server.lua
+120 −0 lib/dns.lua
+18 −0 lib/emitter.lua
+18 −0 lib/error.lua
+18 −0 lib/fiber.lua
+18 −0 lib/fs.lua
+25 −2 lib/http.lua
+136 −0 lib/json.lua
+24 −6 lib/luvit.lua
+18 −0 lib/mime.lua
+207 −0 lib/net.lua
+18 −0 lib/path.lua
+18 −0 lib/pipe.lua
+18 −0 lib/process.lua
+77 −0 lib/querystring.lua
+18 −0 lib/repl.lua
+18 −0 lib/request.lua
+22 −2 lib/response.lua
+26 −3 lib/stack.lua
+18 −0 lib/stream.lua
+18 −0 lib/tcp.lua
+18 −0 lib/timer.lua
+18 −0 lib/tty.lua
+18 −0 lib/udp.lua
+21 −2 lib/url.lua
+38 −0 lib/utils.lua
+0 −18 license.txt
+12 −12 luvit.gyp
+21 −0 src/lconstants.c
+17 −0 src/lconstants.h
+17 −0 src/lenv.c
+17 −0 src/lenv.h
+17 −0 src/lhttp_parser.c
+17 −0 src/lhttp_parser.h
+33 −2 src/luv.c
+17 −0 src/luv.h
+577 −0 src/luv_dns.c
+44 −0 src/luv_dns.h
+22 −4 src/luv_fs.c
+17 −0 src/luv_fs.h
+19 −2 src/luv_fs_watcher.c
+17 −0 src/luv_fs_watcher.h
+19 −2 src/luv_handle.c
+17 −0 src/luv_handle.h
+24 −6 src/luv_misc.c
+17 −0 src/luv_misc.h
+20 −2 src/luv_pipe.c
+17 −0 src/luv_pipe.h
+44 −0 src/luv_portability.h
+21 −3 src/luv_process.c
+17 −0 src/luv_process.h
+28 −7 src/luv_stream.c
+17 −0 src/luv_stream.h
+27 −22 src/luv_tcp.c
+17 −0 src/luv_tcp.h
+23 −5 src/luv_timer.c
+17 −0 src/luv_timer.h
+21 −3 src/luv_tty.c
+17 −0 src/luv_tty.h
+24 −5 src/luv_udp.c
+17 −14 src/luv_udp.h
+48 −5 src/luvit.c
+16 −0 src/luvit.h
+561 −0 src/lyajl.c
+28 −0 src/lyajl.h
+51 −4 src/utils.c
+26 −0 src/utils.h
+33 −1 tests/modules/helper.lua
+115 −0 tests/test-dns.lua
+57 −0 tests/test-net.lua
+18 −0 tests/test-path.lua
+38 −0 tests/test-querystring.lua
+18 −0 tests/test-require.lua
+19 −1 tests/test-tcp.lua
+18 −0 tests/test-timer.lua
+27 −0 tools/lame_sed.py
48 changes: 48 additions & 0 deletions jsonbench.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local JSON = require "json"
local os = require "os"
local table = require "table"


local nLoop = 30

function makeiary(n)
local out={}
for i=1,n do table.insert(out,i) end
return out
end
function makestr(n)
local out=""
for i=1,n-1 do out = out .. "a" end
out = out .. "b"
return out
end

local datasets = {
{ "empty", nLoop*1000, {} },
{ "iary1", nLoop*1000, {1} },
{ "iary10", nLoop*100, {1,2,3,4,5,6,7,8,9,10} },
{ "iary100", nLoop*10, makeiary(100) },
{ "iary1000", nLoop*10, makeiary(1000) },
{ "iary10000", nLoop, makeiary(10000) },
{ "str1", nLoop*1000, "a" },
{ "str10", nLoop*1000, makestr(10) },
{ "str100", nLoop*1000, makestr(100) },
{ "str500", nLoop*1000, makestr(500) },
{ "str1000", nLoop*1000, makestr(1000) },
{ "str10000", nLoop*100, makestr(10000) },
}

for i,v in ipairs(datasets) do
st = os.clock()
local nLoop = v[2]
local offset,res
for j=1, nLoop do
offset,res = JSON.parse( JSON.stringify( v[3] ) )
end
assert(offset)
local et = os.clock()
local t = et - st

print( "json:", v[1], t, "sec", nLoop/t, "times/sec" )

end
4 changes: 2 additions & 2 deletions mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static size_t mpwbuf_pack_number( mpwbuf_t *b, lua_Number n ) {
memcpy(buf+1, &v,2);
len=1+2;
} else if( lv >= -2147483648LL ){
long v = htonl(lv&0xffffffff);
int v = htonl(lv&0xffffffff);
buf[0] = 0xd2;
memcpy(buf+1,&v,4);
len=1+4;
Expand Down Expand Up @@ -452,7 +452,7 @@ static void mprbuf_unpack_anytype( mprbuf_t *b, lua_State *L ) {
break;
case 0xd2: // 32bit neg int
if(mprbuf_left(b)>=4){
long v = *(long*)(s);
int v = *(long*)(s);
v = ntohl(v);
lua_pushnumber(L,v);
b->ofs += 4;
Expand Down
4 changes: 2 additions & 2 deletions orig_mplua/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CFLAGS=$(shell luvit-config --cflags) -arch i386 -g -O3
LIBS=$(shell luvit-config --libs) -arch i386 ../deps/luvit/deps/luajit/src/libluajit.a
CFLAGS=$(shell luvit-config --cflags) -g -O3
LIBS=$(shell luvit-config --libs) ../deps/luvit/deps/luajit/src/libluajit.a

all: msgpackorig.luvit

Expand Down
2 changes: 1 addition & 1 deletion test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ for i=1,#data do -- 0 tests nil!
if not deepcompare(res,data[i]) then
display("expected",data[i])
display("found",res)
assert(false,string.format("wrong value %d",i))
assert(false,string.format("wrong value in case %d",i))
end
end
print(" OK")
Expand Down

0 comments on commit 3592c08

Please sign in to comment.