Type switches
Walk 100k heterogeneous values and dispatch by runtime type. Tests the type-assertion / type-switch path.
Runtime · median per inner-loop window
Full statistics
| Runner | N | Compile | Runtime | P95 | Stddev | RSS | vs piko | Status |
|---|---|---|---|---|---|---|---|---|
| Native Gocompiled | 10 | 182 ms | 567 µs | 605 µs | 15.0 µs | 69 MiB | 0.01× | OK |
| Piko interpbytecode VM | 10 | 1.53 ms | 75.1 ms | 96.8 ms | 6.52 ms | 151 MiB | 1.00× | OK |
| CPython 3.13bytecode VM | 10 | 434 µs | 130 ms | 131 ms | 1.98 ms | n/a | 1.73× | OK |
| PyPy 7.3tracing JIT | 10 | 365 µs | 26.9 ms | 31.0 ms | 1.38 ms | n/a | 0.36× | OK |
| tengobytecode VM | 10 | 307 µs | 153 ms | 160 ms | 2.78 ms | 1.49 GiB | 2.04× | OK |
| scriggobytecode VM | 10 | 490 µs | 127 ms | 132 ms | 1.89 ms | 908 MiB | 1.70× | OK |
| mvmbytecode VM | 10 | 403 µs | 146 ms | 168 ms | 9.84 ms | 67 MiB | 1.94× | OK |
| yaegiAST walker | 10 | 523 µs | 317 ms | 345 ms | 19.6 ms | 78 MiB | 4.22× | OK |
Workload & symmetry rules
Workload
Build a slice of 100,000 heterogeneous values mixing *IntVal, *StringVal, *BytesVal, *BoolVal, and *FloatVal. Walk the slice; for each value, dispatch by runtime type:
*IntVal→(v + 1234) & 0xFFFFFFFF*StringVal→fnv1a32(v)*BytesVal→ XOR-fold of bytes*BoolVal→0or1*FloatVal→uint32(v) & 0xFFFFFFFF
XOR every result into a uint32 accumulator.
Symmetry rules
- Go uses a real
switch v := v.(type)block; Python usesisinstance(...)if/elif equivalents. - No virtual method on the values themselves (that would be bench 13).
Why this benchmark exists
Distinct path from virtual dispatch and from generic dispatch. Measures the cost of runtime type discrimination in a hot loop.
Source code
piko / Go
piko_source.gonative Go
native_main.goCPython / PyPy
cpython.pytengo
script.tengo