1

我已经做了一些基准测试(lua-benchmarks)。由于某种原因,sol2 的执行速度比 LuaBridge3 慢。
在 sol2 repo 中,您可以找到显示 sol2 必须优于 LuaBridge3 ( benchmarks ) 的基准测试,但出于某种原因,在实际用例中并非如此。
在 LuaBridge3 文档中,您可以找到该语句(LuaBridge3 文档):

虽然它接近最高可能的性能,但 LuaBridge 并不是最快的,OOLua 和 sol2 在某些测试中优于 LuaBridge,但它们也更大且编译速度更慢。

那么,为什么 sol2 在我的基准测试中比较慢呢?

Sol2 基准测试:

Performing Sol3 Benchmark:
Time elapsed (Increment (Lua)): 225.012ms
Time elapsed (Increment (C++)): 210.341ms

Time elapsed (String Argument (Lua)): 400.203ms
Time elapsed (String Argument (C++)): 241.732ms

Time elapsed (String Const Argument (Lua)): 405.579ms
Time elapsed (String Const Argument (C++)): 267.502ms

Time elapsed (String View Argument (Lua)): 321.18ms
Time elapsed (String View Argument (C++)): 258.553ms

Time elapsed (String Char Argument (Lua)): 311.116ms
Time elapsed (String Char Argument (C++)): 244.752ms

Time elapsed (String Iterator (Lua)): 561.75ms
Time elapsed (String Iterator (C++)): 188.024ms

Time elapsed (String Const Iterator (Lua)): 555.881ms
Time elapsed (String Const Iterator (C++)): 215.2ms

Time elapsed (String View Iterator (Lua)): 462.316ms
Time elapsed (String View Iterator (C++)): 205.954ms

Time elapsed (String Char Iterator (Lua)): 456.837ms
Time elapsed (String Char Iterator (C++)): 197.267ms

Time elapsed (String Internal Iterator (Lua)): 28.6687ms

Time elapsed (Class passing (Lua)): 491.857ms
Time elapsed (Class Passing (C++)): 188.96ms

Time elapsed (Class Getting (Lua)): 444.842ms
Time elapsed (Class Getting (C++)): 87.885ms

Time elapsed (Class method call (Base Class)): 1018.63ms
Time elapsed (Class method call (Derived Overwritten Class)): 950.832ms
Time elapsed (Class method call (Derived Not Overwritten Class)): 1672.24ms

Time elapsed (Class field access (Base Class)): 837.028ms
Time elapsed (Class field access (Derived Class)): 1512.29ms

LuaBridge3 基准测试:

Performing LuaBridge3 Benchmark:
Time elapsed (Increment (Lua)): 85.4452ms
Time elapsed (Increment (C++)): 685.158ms

Time elapsed (String Argument (Lua)): 187.733ms
Time elapsed (String Argument (C++)): 711.398ms

Time elapsed (String Const Argument (Lua)): 191.785ms
Time elapsed (String Const Argument (C++)): 740.246ms

Time elapsed (String View Argument (Lua)): 149.068ms
Time elapsed (String View Argument (C++)): 725.589ms

Time elapsed (String Char Argument (Lua)): 118.564ms
Time elapsed (String Char Argument (C++)): 718.35ms

Time elapsed (String Iterator (Lua)): 255.276ms
Time elapsed (String Iterator (C++)): 728.269ms

Time elapsed (String Const Iterator (Lua)): 257.562ms
Time elapsed (String Const Iterator (C++)): 756.581ms

Time elapsed (String View Iterator (Lua)): 194.296ms
Time elapsed (String View Iterator (C++)): 738.581ms

Time elapsed (String Char Iterator (Lua)): 170.795ms
Time elapsed (String Char Iterator (C++)): 737.091ms

Time elapsed (String Internal Iterator (Lua)): 5.10969ms

Time elapsed (Class passing (Lua)): 141.677ms
Time elapsed (Class Passing (C++)): 489.28ms

Time elapsed (Class Getting (Lua)): 205.569ms
Time elapsed (Class Getting (C++)): 507.022ms

Time elapsed (Class method call (Base Class)): 154.02ms
Time elapsed (Class method call (Derived Overwritten Class)): 155.294ms
Time elapsed (Class method call (Derived Not Overwritten Class)): 248.309ms

Time elapsed (Class field access (Base Class)): 181.451ms
Time elapsed (Class field access (Derived Class)): 283.496ms

UPD:
Sol2 基准测试(带有 -O3 标志):

Performing Sol3 Benchmark:
Time elapsed (Increment (Lua)): 32.6984ms
Time elapsed (Increment (C++)): 56.1082ms
Time elapsed (String Argument (Lua)): 73.2311ms
Time elapsed (String Argument (C++)): 155.397ms
Time elapsed (String Const Argument (Lua)): 69.815ms
Time elapsed (String Const Argument (C++)): 176.076ms
Time elapsed (String View Argument (Lua)): 59.6035ms
Time elapsed (String View Argument (C++)): 158.813ms
Time elapsed (String Char Argument (Lua)): 53.9835ms
Time elapsed (String Char Argument (C++)): 194.122ms
Time elapsed (String Iterator (Lua)): 116.469ms
Time elapsed (String Iterator (C++)): 88.9511ms
Time elapsed (String Const Iterator (Lua)): 114.828ms
Time elapsed (String Const Iterator (C++)): 99.197ms
Time elapsed (String View Iterator (Lua)): 85.6064ms
Time elapsed (String View Iterator (C++)): 91.3165ms
Time elapsed (String Char Iterator (Lua)): 109.081ms
Time elapsed (String Char Iterator (C++)): 123.287ms
Time elapsed (String Internal Iterator (Lua)): 30.3189ms
Time elapsed (Class passing (Lua)): 155.851ms
Time elapsed (Class Passing (C++)): 88.1614ms
Time elapsed (Class Getting (Lua)): 122.943ms
Time elapsed (Class Getting (C++)): 42.5303ms
Time elapsed (Class method call (Base Class)): 261.55ms
Time elapsed (Class method call (Derived Overwritten Class)): 201.069ms
Time elapsed (Class method call (Derived Not Overwritten Class)): 473.373ms
Time elapsed (Class field access (Base Class)): 214.91ms
Time elapsed (Class field access (Derived Class)): 429.851ms

LuaBridge3 基准测试(带有 -O3 标志):

Performing LuaBridge3 Benchmark:
Time elapsed (Increment (Lua)): 24.6991ms
Time elapsed (Increment (C++)): 169.714ms
Time elapsed (String Argument (Lua)): 56.6672ms
Time elapsed (String Argument (C++)): 160.134ms
Time elapsed (String Const Argument (Lua)): 59.1771ms
Time elapsed (String Const Argument (C++)): 183.209ms
Time elapsed (String View Argument (Lua)): 29.8749ms
Time elapsed (String View Argument (C++)): 164.018ms
Time elapsed (String Char Argument (Lua)): 29.6969ms
Time elapsed (String Char Argument (C++)): 168.75ms
Time elapsed (String Iterator (Lua)): 85.9382ms
Time elapsed (String Iterator (C++)): 152.362ms
Time elapsed (String Const Iterator (Lua)): 83.0993ms
Time elapsed (String Const Iterator (C++)): 178.119ms
Time elapsed (String View Iterator (Lua)): 52.2461ms
Time elapsed (String View Iterator (C++)): 153.509ms
Time elapsed (String Char Iterator (Lua)): 51.528ms
Time elapsed (String Char Iterator (C++)): 163.818ms
Time elapsed (String Internal Iterator (Lua)): 6.12704ms
Time elapsed (Class passing (Lua)): 73.1719ms
Time elapsed (Class Passing (C++)): 157.952ms
Time elapsed (Class Getting (Lua)): 125.278ms
Time elapsed (Class Getting (C++)): 119.256ms
Time elapsed (Class method call (Base Class)): 107.476ms
Time elapsed (Class method call (Derived Overwritten Class)): 111.158ms
Time elapsed (Class method call (Derived Not Overwritten Class)): 196.297ms
Time elapsed (Class field access (Base Class)): 143.778ms
Time elapsed (Class field access (Derived Class)): 234.974ms
4

0 回答 0