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的更多相关文章
随机推荐
- BZOJ 3211 题解
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 2549 Solved: 946[Submit][Status][Discus ...
- 编码Q&A
Q:什么是编码? A:由于计算机中所有数据都是以二进制存在,那么为了存储数字,字母,各种符号和文字,计算机必须用一套映射系统来对应.比如我在某台计算机上规定,用00010001这个二进制数表示字母a, ...
- CentOS VirtualBox启动虚拟及报错:VirtualBox error: Kernel driver not installed (rc=1908)
VirtualBox error: Kernel driver not installed (rc=1908) Hi all, Let me first say that this is my fin ...
- 在DataGridView控件中加入ComboBox下拉列表框的实现
在DataGridView控件中加入ComboBox下拉列表框的实现 转自:http://www.cnblogs.com/luqingfei/archive/2007/03/28/691372.htm ...
- CSS的class、id、css文件名的常用命名规则
CSS的class.id.css文件名的常用命名规则 (一)常用的CSS命名规则 头:header 内容:content/container 尾:footer ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...
- [LintCode] House Robber III 打家劫舍之三
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- php内网探测脚本&简单代理访问
<?php $url = isset($_REQUEST['u'])?$_REQUEST['u']:null; $ip = isset($_REQUEST['i'])?$_REQUEST['i' ...
- JAVA6开发WebService (三)——几个概念
转载自http://wuhongyu.iteye.com/blog/808922 要了解WebService,光能写代码不行啊,这说说WebService最基本的概念. 首先WebService要知道 ...
- JS验证只允许输入数字
1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafter ...