Benchmark results
These CPU times were measured on 2026-12-02 with bench_mark built Release (-O3 -DNDEBUG) after the pattern engine (PR #68), native call-site fast path (PR #70), and zero-copy string.find / class-prefix scan (PR #71) optimizations, plus benchmark fixes for MultiReturn, TablePack, and ToString.
Environment
- Date: 2026-12-02
- Machine: Intel(R) Xeon(R) Processor, 4 vCPU, 2.4 GHz (pinned to core 0)
- Build: GCC 13.3.0, Release
-O3 -DNDEBUG
- Lua: 5.4.8
- Command:
taskset -c 0 ./bench_mark --benchmark_min_time=0.2s --benchmark_repetitions=1
Each row uses the largest registered argument. INTERP/Lua is interpreter time divided by Lua time, so a value above 1 means the interpreter is slower and a value below 1 means the interpreter is faster. GCC/Lua and TCC/Lua are Lua time divided by that backend, so a value above 1 means FakeLua is faster. C++ empty loops that the compiler deletes are not used as a GCC comparison.
What this run shows
- GCC beats Lua 5.4.8 on 50 of 51 Lua-compared benchmarks. Numeric hotspots lead by 12x–53x (
Recursion 53.15x, Fibonacci 45.06x, Popcount 24.08x, MathSqrt 16.27x, FloatPoly 16.02x and matching handwritten C++, Sum 13.17x, Vector3 12.00x). The only scenario where GCC trails Lua is single-call TablePack (247 ns vs 211 ns, 0.85x), which now invokes real variadic table.pack with 10 arguments.
- String search and Lua 5.4 pattern matching now beat Lua across the board on GCC. Zero-copy
string.find, memchr+memcmp plain scanning, literal-prefix fast scan, and first-byte character-class bitmaps lifted StringFind (plain=true) to 3.22x on GCC (and 2.56x on TCC), StringFindLiteral to 2.77x on GCC (2.28x TCC, 0.42x INTERP), StringGmatch to 1.65x on GCC, StringGsub to 1.12x on GCC, and StringFindPattern to 1.06x on GCC. Delegating TCC’s byte-loop helpers to -O3 host code lifted TCC StringLower/StringUpper to 7.58x / 6.87x Lua.
- Native call-site caching closed the interpreter’s native-call gap. Caching
NativeFuncEntry in the interpreter and avoiding redundant vararg boxing brought MathTrig/MathSqrt/MathExpLog/MathMinMax down to 1.22x–1.38x Lua, TableInsert to 1.22x, Variadic to 2.45x, and pushed TableRemove (0.91x), StringFormat (0.73x), StringByte (0.74x), and ToString (0.93x) faster than Lua 5.4.8 on the interpreter.
- Remaining interpreter gaps are table-access and loop dispatch heavy.
Vector3 (3.42x), NestedTable (2.97x), Fibonacci (2.82x), BubbleSort (2.59x), InsertionSort (2.35x), and BinarySearch (2.21x) are the main remaining >2x scenarios on INTERP.
- Fixed benchmarks reflect real costs.
MultiReturn now actually returns and unpacks 3 values (x, x * 2, x * 3) instead of summing inside the callee (GCC 3.30x, INTERP 2.39x); TablePack now calls table.pack(...) directly instead of manually building a table; BM_CPP_ToString now converts once instead of looping n times (5.4 ns).
- Allocation without GC beats Lua on all three backends, and
NativeObject field ops stay around 7–14 ns. TableChurn, StringChurn, and MixedAlloc are 0.40x–0.56x Lua on INTERP and 7.56x–12.64x on GCC. Deep 8-level NativeObject leaf writes (11.6 ns) match shallow SetInt (10.9 ns).
Algorithms
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| Fibonacci |
32 |
112.9 ms |
318.9 ms |
2.82x |
2.51 ms |
45.06x |
63.6 ms |
1.77x |
| Sum |
5000000 |
16.9 ms |
37.0 ms |
2.20x |
1.28 ms |
13.17x |
6.00 ms |
2.81x |
| Popcount |
100000 |
7.50 ms |
13.9 ms |
1.85x |
311.5 μs |
24.08x |
1.11 ms |
6.73x |
| FloatPoly |
1000000 |
24.5 ms |
38.4 ms |
1.57x |
1.53 ms |
16.02x |
22.3 ms |
1.10x |
| BubbleSort |
200 |
387.1 μs |
1.00 ms |
2.59x |
68.0 μs |
5.69x |
551.4 μs |
0.70x |
| Sieve |
5000 |
143.6 μs |
286.5 μs |
2.00x |
30.7 μs |
4.68x |
158.6 μs |
0.91x |
| InsertionSort |
200 |
273.8 μs |
642.2 μs |
2.35x |
39.5 μs |
6.93x |
426.7 μs |
0.64x |
| BinarySearch |
1000 |
210.0 μs |
464.8 μs |
2.21x |
90.1 μs |
2.33x |
356.9 μs |
0.59x |
| Vector3 |
1000000 |
43.6 ms |
149.2 ms |
3.42x |
3.63 ms |
12.00x |
81.3 ms |
0.54x |
| MatMul |
— |
1.20 μs |
2.01 μs |
1.68x |
310 ns |
3.86x |
1.27 μs |
0.94x |
| GCD |
2147483647/1073741823 |
45.7 ns |
85.9 ns |
1.88x |
44.5 ns |
1.03x |
67.9 ns |
0.67x |
| PowMod |
1234567/7654321/1000000007 |
383 ns |
588 ns |
1.54x |
198 ns |
1.94x |
320 ns |
1.20x |
| FastPow |
1234567/7654321/1000000007 |
364 ns |
552 ns |
1.52x |
201 ns |
1.81x |
258 ns |
1.41x |
Calls
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| EmptyCall |
100000 |
2.23 ms |
3.22 ms |
1.45x |
127.6 μs |
17.45x |
2.59 ms |
0.86x |
| Recursion |
25 |
4.85 ms |
10.9 ms |
2.25x |
91.2 μs |
53.15x |
2.21 ms |
2.19x |
| Closure |
1000 |
89.8 μs |
97.0 μs |
1.08x |
6.26 μs |
14.34x |
79.9 μs |
1.12x |
| MultiReturn |
10000 |
277.3 μs |
663.8 μs |
2.39x |
83.9 μs |
3.30x |
984.7 μs |
0.28x |
| Variadic |
1 |
204 ns |
499 ns |
2.45x |
85.1 ns |
2.39x |
319 ns |
0.64x |
Strings
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| StringLen |
10000 |
781 ns |
217 ns |
0.28x |
199 ns |
3.93x |
218 ns |
3.58x |
| StringSub |
10000 |
1.21 μs |
412 ns |
0.34x |
338 ns |
3.60x |
382 ns |
3.18x |
| StringLower |
10000 |
5.32 μs |
779 ns |
0.15x |
699 ns |
7.61x |
701 ns |
7.58x |
| StringUpper |
10000 |
5.27 μs |
770 ns |
0.15x |
709 ns |
7.42x |
767 ns |
6.87x |
| StringFind |
10000 |
785 ns |
330 ns |
0.42x |
244 ns |
3.22x |
306 ns |
2.56x |
| StringFindLiteral |
10000 |
793 ns |
337 ns |
0.42x |
287 ns |
2.77x |
348 ns |
2.28x |
| StringGsub |
1000 |
16.0 μs |
14.4 μs |
0.90x |
14.4 μs |
1.12x |
14.0 μs |
1.14x |
| StringFindPattern |
1000 |
311.1 μs |
441.6 μs |
1.42x |
294.5 μs |
1.06x |
463.0 μs |
0.67x |
| StringGmatch |
1000 |
429.6 μs |
523.1 μs |
1.22x |
260.3 μs |
1.65x |
352.2 μs |
1.22x |
| StringFormat |
500 |
48.0 μs |
35.2 μs |
0.73x |
3.29 μs |
14.56x |
21.4 μs |
2.25x |
| StringRep |
1000 |
2.70 μs |
1.41 μs |
0.52x |
2.18 μs |
1.24x |
3.40 μs |
0.80x |
| StringReverse |
10000 |
4.37 μs |
3.08 μs |
0.71x |
2.92 μs |
1.50x |
5.39 μs |
0.81x |
| StringByte |
1000 |
186 ns |
138 ns |
0.74x |
82.8 ns |
2.25x |
107 ns |
1.74x |
| StringChar |
500 |
27.3 μs |
29.7 μs |
1.09x |
5.67 μs |
4.82x |
31.8 μs |
0.86x |
| ToNumber |
1 |
69.6 ns |
101 ns |
1.45x |
68.0 ns |
1.02x |
119 ns |
0.59x |
| ToString |
500 |
127 ns |
118 ns |
0.93x |
54.2 ns |
2.35x |
84.0 ns |
1.52x |
Tables
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| TableCreate |
5000 |
58.3 μs |
110.2 μs |
1.89x |
21.7 μs |
2.68x |
98.6 μs |
0.59x |
| TableInsert |
5000 |
172.0 μs |
210.4 μs |
1.22x |
24.8 μs |
6.93x |
130.2 μs |
1.32x |
| TableRemove |
5000 |
325.4 μs |
294.5 μs |
0.91x |
31.6 μs |
10.30x |
240.8 μs |
1.35x |
| TableConcat |
1000 |
112.8 μs |
59.3 μs |
0.53x |
15.9 μs |
7.09x |
44.7 μs |
2.53x |
| TableSort |
1000 |
180.5 μs |
71.8 μs |
0.40x |
48.2 μs |
3.75x |
65.2 μs |
2.77x |
| TableMove |
5000 |
99.8 μs |
156.1 μs |
1.56x |
47.6 μs |
2.10x |
207.1 μs |
0.48x |
| TablePack |
1 |
211 ns |
318 ns |
1.51x |
247 ns |
0.85x |
349 ns |
0.61x |
| HashInsert |
1000 |
174.3 μs |
97.5 μs |
0.56x |
32.9 μs |
5.29x |
125.1 μs |
1.39x |
| HashLookup |
1000 |
128.2 μs |
83.4 μs |
0.65x |
22.3 μs |
5.74x |
68.1 μs |
1.88x |
| NestedTable |
10000 |
880.3 μs |
2.61 ms |
2.97x |
331.9 μs |
2.65x |
2.12 ms |
0.41x |
Math
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| MathTrig |
100000 |
5.78 ms |
7.57 ms |
1.31x |
963.4 μs |
6.00x |
9.05 ms |
0.64x |
| MathSqrt |
100000 |
2.47 ms |
3.02 ms |
1.22x |
152.0 μs |
16.27x |
2.42 ms |
1.02x |
| MathExpLog |
100000 |
5.16 ms |
7.11 ms |
1.38x |
657.1 μs |
7.85x |
7.14 ms |
0.72x |
| MathMinMax |
100000 |
8.00 ms |
10.5 ms |
1.32x |
742.6 μs |
10.77x |
6.85 ms |
1.17x |
Allocation
| Scenario |
Args |
Lua 5.4.8 |
INTERP |
INTERP/Lua |
GCC |
GCC/Lua |
TCC |
TCC/Lua |
| TableChurn |
1000 |
161.3 μs |
90.7 μs |
0.56x |
21.3 μs |
7.56x |
110.6 μs |
1.46x |
| StringChurn |
1000 |
334.1 μs |
133.5 μs |
0.40x |
26.4 μs |
12.64x |
97.2 μs |
3.44x |
| MixedAlloc |
1000 |
315.7 μs |
176.3 μs |
0.56x |
36.3 μs |
8.70x |
153.5 μs |
2.06x |
NativeObject
C++ host-side NativeObject hot-path operations (no Lua counterpart).
| Benchmark |
CPU Time |
BM_NativeObjectSetInt |
10.9 ns |
BM_NativeObjectGetInt |
7.0 ns |
BM_NativeObjectSetString |
13.6 ns |
BM_NativeObjectCreateDestroy |
152 ns |
BM_NativeObjectSetObject |
11.3 ns |
BM_NativeObjectDeepLeafWrite |
11.6 ns |