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的更多相关文章
随机推荐
- ACM 矩形的个数
矩形的个数 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1*2的矩形,2个2*2的矩形,2个3 ...
- 【POJ】3243 Clever Y
http://poj.org/problem?id=3243 题意:求$a^y \equiv b \pmod{p}$最小的$y$.(0<=x, y, p<=10^9) #include & ...
- Oracle 游标使用全解(转)
-- 声明游标:CURSOR cursor_name IS select_statement --For 循环游标 --(1)定义游标 --(2)定义游标变量 --(3)使用for循环来使用这个游标 ...
- (转)as3效率优化
1.改进算法无论对于那一种程序,好的算法总是非常重要的,而且能够极大地提高程序性能,所以任何性能的优化第一步就是从算法或者说程序逻辑的优化开始,检查自己的程序是否有多余的运算,是否在没有必要的时候做了 ...
- js正则验证之不能使用相同字符
在我们的前端开发中,为了不让用户输入相同的密码字符以提高其安全性,我们会写一个js方法来实现这个功能.接下来,我就来实现这个方法,有其他好的解决办法,敬请留言,博主必定向其学习. function _ ...
- js从身份证号中获取出生日期和性别
今天,在做移动端的项目中,按照设计稿的要求,是可以让用户自己输入出生日期的,我还很认真的用了刚刚知道的html5表单的日期类型,本想着终于不用日期插件就可以实现用户选择自己的出生日期了,可结果老大说, ...
- [LintCode] Maximum Gap 求最大间距
Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...
- LaTex Remove Left Margin 去除左边空间
LaTex中使用itemize的时候,默认的每一项左边都有一小段距离,并不是紧贴着边缘的,那么如果我们想去掉这段距离,我们可以使用下面的命令: \usepackage{enumitem} \setli ...
- Maya 脚本控制物体自转
在Maya中,我们可以用脚本来控制物体的自转方向,速度等等,步骤如下: 选择需要操作的物体object,打开通道盒Channel Box,点击编辑Edit,打开表达式Expressions面板 选择需 ...
- mysql主从切换摘要
1.需要提升为主的从库,停止io线程等待slave数据全部更新完毕 stop slave IO_THREAD #show processlist的输出,直到看到状态是Slave has read al ...