lua2c
lua2c
lua2c is a Lua module and utility to convert Lua 5.1 source code to C API code.
http://lua-users.org/wiki/LuaToCee
This utility converts a given Lua source file into an equivalent C source file written in terms of Lua C API calls. At least, this works for a large subset of the Lua language (see limitations below).
基于特定lua版本, 将lua代码转换为 LUA C api实现实现的c代码。 能够满足lua语言的大的子集。
代码:
https://github.com/davidm/lua2c
使用
Example usage:
lua lua2c.lua test/bisect.luawhich generates a C file similar to as shown here: [bisect.c].
可见 功能是使用lua脚本实现。
项目还提供了一个 shell 工具, 可以集成 翻译(lua-》c), 编译(c-》机器码), 执行(execute)于一体。
./clua test/bisect.lua
当然也可以只编译,不运行:
lua2c can even compile itself! (Note: the -c option compiles only without running.)
./clua -c lua2c.lua # compile lua2c binary ./lua2c examples-lua/bisect.lua # test
对比
lua2c的作用猜测是, 提升代码运行效率。
以此项目 bisect.lua 脚本为研究对象, 使用luac将其编译出一份C的版本,
与lua的版本实现做性能对比, 运行 1000次。
C版本运行脚本:
root@fqs:/home/sambadir/lua2c-master/lua2c-master# cat time_c.sh
#!/bin/bash
# while-count: display a series of numbersdate_start=$(date +%s)
count=1
upboundary=1000
while [[ $count -le upboundary ]]; do
./bisect.o
# echo $count
count=$((count + 1))
donedate_end=$(date +%s)
time=`expr $date_end - $date_start`
#time=$($date_end - $date_start)
echo $time
lua版本运行脚本(仅仅运行语句与c不同):
root@fqs:/home/sambadir/lua2c-master/lua2c-master# cat time_lua.sh
#!/bin/bash
# while-count: display a series of numbersdate_start=$(date +%s)
count=1
upboundary=1000
while [[ $count -le upboundary ]]; do
lua ./examples-lua/bisect.lua
# echo $count
count=$((count + 1))
donedate_end=$(date +%s)
time=`expr $date_end - $date_start`
#time=$($date_end - $date_start)
echo $time
虽然脚本中有计算时间的部分, 但是只能达到秒的级别。 为精确计算时间, 我们使用系统的 time工具。
time /bin/bash time_c.sh
结果:
real 0m8.313s
user 0m0.464s
sys 0m0.756s
-----------------------
time /bin/bash time_lua.sh
结果:
real 0m8.770s
user 0m0.720s
sys 0m0.752s
=== 总体上, 是翻译成c之后的版本, 性能好些,但是不明显。 猜测跟脚本内容有关。
lua2c的更多相关文章
随机推荐
- 【BZOJ1901】Zju2112 Dynamic Rankings
Description 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是 ...
- 【BZOJ3122】【SDoi2013】随机数生成器
Description Input 输入含有多组数据,第一行一个正整数T,表示这个测试点内的数据组数. 接下来T行,每行有五个整数p,a,b,X1,t,表示一组数据.保证X1和t都是合法的页码. ...
- iOS 常用英语翻译
1..serve advertisements within the app 服务应用中的广告.如果你的应用中集成了广告的时候,你需要勾选这一项. √2.Attribute this app in ...
- weblogic 11g 配置db2数据源
配置db2数据源可以直接在包里面配置,不需要专门在服务器上配置数据源. 在11g版本前要配置db2数据源是需要增加包,后续的版本处理了这个问题. 1. 将C:\Program Files\SQLLIB ...
- About-PHP-02
如果要给table里面的td添加颜色,有两种方法: <html> <head> <meta http-equiv="Content-Type" con ...
- 11877 The Coco-Cola Store
题目: 11877 The Coco-Cola Store Once upon a time, there is a special coco-cola store. If you retur ...
- org.hibernate.hql.ast.QuerySyntaxException: XXX is not mapped
因为 String sql2 = "select s from Student s where s.clazz.name=:name"; 此处的 Student 应该为类名.hql ...
- php中提示Undefined index的解决方法
我们经常接收表单POST过来的数据时报Undefined index错误,如下: $act=$_POST['action']; 用以上代码总是提示 Notice: Undefined index: a ...
- js 原生 ajax 异步上传图片
<script type="text/javascript"> function upload() { var file1 = document.getElementB ...
- 微信APP支付Java后端回调处理
package com.gaoxiao.framework.controller.gaojia; import com.gaoxiao.framework.commonfiles.entity.Sta ...