gopher-lua初步了解

最近看到golang里面有人实现了一套lua的调用库。
go-lua
https://github.com/yuin/gopher-lua
github.com/aarzilli/golua/lua

性能对比
This exercises the call stack implementation. When computing fib(35), go-lua is about 6x slower than the C Lua interpreter. Gopher-lua is about 20% faster than go-lua. Much of the performance difference between go-lua and gopher-lua comes from the inclusion of debug hooks in go-lua. The remainder is due to the call stack implementation - go-lua heap-allocates Lua stack frames with a separately allocated variant struct, as outlined above. Although it caches recently used stack frames, it is outperformed by the simpler statically allocated call stacks in gopher-lua.

  $ time lua fibr.lua
  real  0m2.807s
  user  0m2.795s
  sys   0m0.006s

  $ time glua fibr.lua
  real  0m14.528s
  user  0m14.513s
  sys   0m0.031s

  $ time go-lua fibr.lua
  real  0m17.411s
  user  0m17.514s
  sys   0m1.287s

这套方案,是使用golang完整编写了一套lua vm,性能非常差。而且这套东西是不能兼容使用C语言编写的三方库lua库,打比方就是protobuf-c的库就无法使用。其实这样就局限了这套代码的用途了。如果是使用来编写一些简单的逻辑,是可以的。做做配置也是不错,但是其他的事情,这个是不合适的。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容