说我有一个cdata
变量(FFI查询的结果)。然后,将其字段复制到Lua表中。更快的方法是:Lua表或原始cdata
变量的访问字段?
让我们检查一下
使用jit:
./tarantool -l clock -l ffi
Tarantool 2.3.1-18-ga5a2bb28a
type 'help' for interactive help
tarantool> ffi.cdef[[ typedef struct test { int field; } ]]
---
...
tarantool> T = ffi.typeof('struct test')
---
...
tarantool> F = T({12345})
---
...
tarantool> L = {field = 12345}
---
...
tarantool> local st = clock.proc() for i=1,1e8 do local x = F.field end return clock.proc() - st
---
- 0.036895
...
tarantool> local st = clock.proc() for i=1,1e8 do local x = L.field end return clock.proc() - st
---
- 0.037841
...
并且没有jit:
tarantool> jit.off()
---
...
tarantool> local st = clock.proc() for i=1,1e6 do local x = F.field end return clock.proc() - st
---
- 0.198209
...
tarantool> local st = clock.proc() for i=1,1e6 do local x = L.field end return clock.proc() - st
---
- 0.010116
...