最近一直在慢慢了解各种脚本语言嵌入C++、相互调用的方式以及性能。一共涉及Python, Lua, Luaplus, LuaBind, Mono C#等几种方式。
总结如下:
1.先上脚本性能 C# vs Lua
C# Mono used what fraction? used how many times more? | ||||
---|---|---|---|---|
Benchmark | Time | Memory | Code | |
fannkuch-redux | 1/31 | 17× | ± | |
n-body | 1/21 | 17× | ± | |
mandelbrot | 1/16 | 46× | 2× | |
spectral-norm | 1/8 | 15× | 3× | |
reverse-complement | 1/8 | 1/4 | 2× | |
fasta | 1/7 | 13× | ± | |
binary-trees | 1/5 | 1/4 | ± | |
k-nucleotide | 1/2 | ± | 2× | |
pidigits | 2× | 10× | 2× | |
regex-dna | 2× | 2× | ± |
C# Mono used what fraction? used how many times more? | |||||||
---|---|---|---|---|---|---|---|
Time-used | |- | |--- | 25% | median | 75% | ---| | -| |
(Elapsed secs) | 1/31 | 1/31 | 1/16 | 1/7 | 1/2 | ± | 2× |
python3 vs lua
Python 3 used what fraction? used how many times more? | ||||
---|---|---|---|---|
Benchmark | Time | Memory | Code | |
reverse-complement | 1/3 | ± | 1/2 | |
regex-dna | 1/2 | 1/2 | ± | |
binary-trees | ± | ± | ± | |
fannkuch-redux | ± | 6× | ± | |
pidigits | ± | 4× | 1/2 | |
k-nucleotide | 2× | 1/2 | ± | |
n-body | 2× | 6× | ± | |
mandelbrot | 2× | 70× | 2× | |
spectral-norm | 4× | 6× | ± | |
fasta | 5× | 4× | ± |
Python 3 used what fraction? used how many times more? | |||||||
---|---|---|---|---|---|---|---|
Time-used | |- | |--- | 25% | median | 75% | ---| | -| |
(Elapsed secs) | 1/3 | 1/3 | ± | 2× | 2× | 4× | 5× |
脚本功能:注册全局函数到脚本,注册类成员到脚本,注册类方法到脚本,脚本生成c++类,调用脚本函数,脚本函数以c++类为参数(注册类对象到脚本),Unicode支持,继承支持
1.luaPlus: 不支持继承。支持其他。但是对于调用脚本函数并且有c++对象作为参数还比较麻烦。需要进行绑定metatable和解绑的过程