Skip to content

Instantly share code, notes, and snippets.

@fwsGonzo
Last active October 11, 2025 10:42
Show Gist options
  • Save fwsGonzo/9132f0ef7d3f009baa5b222eedf392da to your computer and use it in GitHub Desktop.
Save fwsGonzo/9132f0ef7d3f009baa5b222eedf392da to your computer and use it in GitHub Desktop.
Benchmark between libriscv and LuaJIT
$ ./bench
* All benchmark results are measured in 200x1200 samples
benchmark overhead median 0ns lowest: 0ns highest: 0ns
Self-test running ELF entry at 0x10C20
Calling into event loop...!
event_loop: Checking for work
event_loop: Going to sleep!
add_work: Adding work
Resuming event loop...!
event_loop: Checking for work
work: Doing some work!
event_loop: Going to sleep!
event_loop: Checking for work
event_loop: Going to sleep!
add_work: Adding work
event_loop: Checking for work
work: Doing some work!
event_loop: Going to sleep!
RISC-V self-test OK
* Loading program of size 202739 from 0x78e52a0513c0 to virtual 0x10000 -> 0x417f3
* Program segment readable: 1 writable: 0 executable: 1
* Loading program of size 2096 from 0x78e52a082bb4 to virtual 0x427f4 -> 0x43024
* Program segment readable: 1 writable: 1 executable: 0
* Using program-provided exit function at 0x119c8
libriscv: Found embedded translation for hash 9077D2DD, 29/5663 mappings
* Entry is at 0x10c20
libriscv: mips instr 1600020000, time 1.224121, 1307.076475 mip/s
libriscv: call overhead median 2ns lowest: 2ns highest: 3ns
libriscv: call args=1 median 6ns lowest: 6ns highest: 11ns
libriscv: call args=2 median 6ns lowest: 6ns highest: 9ns
libriscv: call args=3 median 6ns lowest: 6ns highest: 11ns
libriscv: call args=4 median 6ns lowest: 6ns highest: 8ns
libriscv: call args=5 median 6ns lowest: 6ns highest: 6ns
libriscv: call args=6 median 6ns lowest: 6ns highest: 9ns
libriscv: call args=7 median 6ns lowest: 6ns highest: 9ns
libriscv: call args=8 median 6ns lowest: 6ns highest: 6ns
libriscv: preempt overhead median 10ns lowest: 10ns highest: 14ns
libriscv: resume execution median 4ns lowest: 4ns highest: 7ns
luajit: call overhead median 152ns lowest: 149ns highest: 161ns
luajit: call args=1 median 161ns lowest: 159ns highest: 172ns
luajit: call args=2 median 165ns lowest: 163ns highest: 173ns
luajit: call args=3 median 168ns lowest: 166ns highest: 176ns
luajit: call args=4 median 173ns lowest: 170ns highest: 185ns
luajit: call args=5 median 175ns lowest: 172ns highest: 185ns
luajit: call args=6 median 177ns lowest: 175ns highest: 187ns
luajit: call args=7 median 181ns lowest: 179ns highest: 191ns
luajit: call args=8 median 184ns lowest: 182ns highest: 192ns
libriscv: syscall args=0 median 3ns lowest: 3ns highest: 4ns
libriscv: syscall args=1 median 5ns lowest: 5ns highest: 9ns
libriscv: syscall args=2 median 5ns lowest: 5ns highest: 7ns
libriscv: syscall args=3 median 5ns lowest: 5ns highest: 8ns
libriscv: syscall args=4 median 5ns lowest: 5ns highest: 7ns
libriscv: syscall args=5 median 5ns lowest: 5ns highest: 7ns
libriscv: syscall args=6 median 5ns lowest: 5ns highest: 9ns
libriscv: syscall args=7 median 5ns lowest: 5ns highest: 8ns
libriscv: syscall string median 7ns lowest: 6ns highest: 10ns
luajit: syscall args=0 median 168ns lowest: 165ns highest: 177ns
luajit: syscall args=1 median 182ns lowest: 179ns highest: 196ns
luajit: syscall args=2 median 195ns lowest: 192ns highest: 204ns
luajit: syscall args=3 median 208ns lowest: 204ns highest: 218ns
luajit: syscall args=4 median 223ns lowest: 219ns highest: 233ns
luajit: syscall args=5 median 235ns lowest: 231ns highest: 248ns
luajit: syscall args=6 median 249ns lowest: 245ns highest: 259ns
luajit: syscall args=7 median 262ns lowest: 257ns highest: 270ns
luajit: syscall string median 179ns lowest: 176ns highest: 188ns
After this point, call overhead is subtracted from every benchmark result for both libriscv and Lua
libriscv: array append median 4ns lowest: 4ns highest: 6ns
libriscv: vector append median 5ns lowest: 5ns highest: 7ns
luajit: table append median 19ns lowest: 15ns highest: 27ns
libriscv: 8x arguments median 20ns lowest: 20ns highest: 29ns
libriscv: 8x stored args median 16ns lowest: 16ns highest: 20ns
libriscv: 8x prepared args median 20ns lowest: 19ns highest: 25ns
luajit: 8x arguments median 369ns lowest: 361ns highest: 379ns
libriscv: integer math median 5ns lowest: 4ns highest: 8ns
libriscv: fp math median 7ns lowest: 7ns highest: 11ns
libriscv: exp math median 9ns lowest: 9ns highest: 13ns
libriscv: fib(40) median 3ns lowest: 3ns highest: 6ns
libriscv: taylor(1K) median 612ns lowest: 600ns highest: 635ns
luajit: integer math median 47ns lowest: 42ns highest: 55ns
luajit: fp math median 58ns lowest: 55ns highest: 66ns
luajit: exp math median 65ns lowest: 62ns highest: 80ns
luajit: fib(40) median 59ns lowest: 55ns highest: 67ns
luajit: taylor(1K) median 882ns lowest: 840ns highest: 924ns
libriscv: complex syscall median 30ns lowest: 30ns highest: 34ns
luajit: complex syscall median 840ns lowest: 830ns highest: 865ns
libriscv: micro threads median 91ns lowest: 88ns highest: 100ns
luajit: coroutines median 162ns lowest: 156ns highest: 188ns
libriscv: micro thread args median 106ns lowest: 104ns highest: 113ns
libriscv: full thread args median 118ns lowest: 115ns highest: 125ns
luajit: coroutine args median 210ns lowest: 203ns highest: 227ns
luajit: coroutine args median 258ns lowest: 249ns highest: 268ns
libriscv: naive memcpy median 1044ns lowest: 999ns highest: 1056ns
libriscv: syscall memcpy median 14ns lowest: 13ns highest: 17ns
luajit: memcpy median 93ns lowest: 84ns highest: 102ns
libriscv: syscall memset median 9ns lowest: 8ns highest: 19ns
libriscv: naive memset median 262ns lowest: 172ns highest: 278ns
luajit: memset median 66ns lowest: 63ns highest: 77ns
libriscv: sieve(10M) median 39ms lowest: 39ms highest: 39ms
luajit: sieve(10M) median 130ms lowest: 130ms highest: 130ms
@fwsGonzo
Copy link
Author

fwsGonzo commented Jun 4, 2024

libriscv with TCC (as a form of JIT) against LuaJIT

$ ./bench 
* All benchmark results are measured in 200x1200 samples
              benchmark overhead	median 0ns  		lowest: 0ns     	highest: 0ns
Self-test running ../rv32-binary ELF entry at 0x10C20
Calling into event loop...!
event_loop: Checking for work
event_loop: Going to sleep!
add_work: Adding work
Resuming event loop...!
event_loop: Checking for work
work: Doing some work!
event_loop: Going to sleep!
event_loop: Checking for work
event_loop: Going to sleep!
add_work: Adding work
event_loop: Checking for work
work: Doing some work!
event_loop: Going to sleep!
RISC-V self-test OK
* Loading program of size 203759 from 0x74c1d504afc0 to virtual 0x10000 -> 0x41bef
* Program segment readable: 1 writable: 0  executable: 1
* Loading program of size 2100 from 0x74c1d507cbb0 to virtual 0x42bf0 -> 0x43424
* Program segment readable: 1 writable: 1  executable: 0
* Using program-provided exit function at 0x11b30
libriscv: No embedded translation found for hash B1B8A2E6
libriscv: Emitted 40417 accelerated instructions, 8 blocks and 5716 functions. GP=0x43AB8
libriscv: 695 mappings for f_100b4
libriscv: 907 mappings for f_1506c
libriscv: 825 mappings for f_19fcc
libriscv: 826 mappings for f_1ee0c
libriscv: 774 mappings for f_23f7c
libriscv: 875 mappings for f_28dcc
libriscv: 639 mappings for f_2fe7c
libriscv: 175 mappings for f_35838
libriscv: Activated libtcc binary translation with hash 0xB1B8A2E6, 8/5716 mappings
* Entry is at 0x10c20
                  libriscv: mips	instr 1600020000, time 1.171710, 1365.542619 mip/s
         libriscv: call overhead	median 2ns  		lowest: 2ns     	highest: 5ns
           libriscv: call args=1	median 7ns  		lowest: 7ns     	highest: 14ns
           libriscv: call args=2	median 8ns  		lowest: 8ns     	highest: 10ns
           libriscv: call args=3	median 8ns  		lowest: 8ns     	highest: 50ns
           libriscv: call args=4	median 8ns  		lowest: 8ns     	highest: 8ns
           libriscv: call args=5	median 8ns  		lowest: 8ns     	highest: 32ns
           libriscv: call args=6	median 8ns  		lowest: 7ns     	highest: 29ns
           libriscv: call args=7	median 8ns  		lowest: 8ns     	highest: 37ns
           libriscv: call args=8	median 7ns  		lowest: 7ns     	highest: 28ns
      libriscv: preempt overhead	median 13ns  		lowest: 12ns     	highest: 36ns
      libriscv: resume execution	median 6ns  		lowest: 6ns     	highest: 8ns
           luajit: call overhead	median 156ns  		lowest: 154ns     	highest: 186ns
             luajit: call args=1	median 166ns  		lowest: 164ns     	highest: 193ns
             luajit: call args=2	median 172ns  		lowest: 170ns     	highest: 264ns
             luajit: call args=3	median 177ns  		lowest: 174ns     	highest: 194ns
             luajit: call args=4	median 183ns  		lowest: 181ns     	highest: 199ns
             luajit: call args=5	median 185ns  		lowest: 183ns     	highest: 203ns
             luajit: call args=6	median 190ns  		lowest: 188ns     	highest: 214ns
             luajit: call args=7	median 194ns  		lowest: 192ns     	highest: 209ns
             luajit: call args=8	median 197ns  		lowest: 195ns     	highest: 215ns

        libriscv: syscall args=0	median 10ns  		lowest: 10ns     	highest: 13ns
        libriscv: syscall args=1	median 10ns  		lowest: 10ns     	highest: 12ns
        libriscv: syscall args=2	median 10ns  		lowest: 10ns     	highest: 47ns
        libriscv: syscall args=3	median 10ns  		lowest: 10ns     	highest: 16ns
        libriscv: syscall args=4	median 10ns  		lowest: 10ns     	highest: 13ns
        libriscv: syscall args=5	median 10ns  		lowest: 10ns     	highest: 70ns
        libriscv: syscall args=6	median 10ns  		lowest: 10ns     	highest: 12ns
        libriscv: syscall args=7	median 10ns  		lowest: 10ns     	highest: 17ns
        libriscv: syscall string	median 13ns  		lowest: 13ns     	highest: 45ns
          luajit: syscall args=0	median 174ns  		lowest: 170ns     	highest: 212ns
          luajit: syscall args=1	median 187ns  		lowest: 185ns     	highest: 205ns
          luajit: syscall args=2	median 203ns  		lowest: 200ns     	highest: 226ns
          luajit: syscall args=3	median 218ns  		lowest: 216ns     	highest: 239ns
          luajit: syscall args=4	median 233ns  		lowest: 230ns     	highest: 247ns
          luajit: syscall args=5	median 246ns  		lowest: 243ns     	highest: 338ns
          luajit: syscall args=6	median 261ns  		lowest: 260ns     	highest: 279ns
          luajit: syscall args=7	median 274ns  		lowest: 272ns     	highest: 286ns
          luajit: syscall string	median 186ns  		lowest: 183ns     	highest: 202ns

After this point, call overhead is subtracted from every benchmark result for both libriscv and Lua

          libriscv: array append	median 5ns  		lowest: 5ns     	highest: 9ns
         libriscv: vector append	median 6ns  		lowest: 6ns     	highest: 34ns
            luajit: table append	median 18ns  		lowest: 15ns     	highest: 54ns

          libriscv: 8x arguments	median 26ns  		lowest: 26ns     	highest: 42ns
        libriscv: 8x stored args	median 23ns  		lowest: 22ns     	highest: 54ns
      libriscv: 8x prepared args	median 38ns  		lowest: 37ns     	highest: 69ns
            luajit: 8x arguments	median 383ns  		lowest: 374ns     	highest: 406ns

          libriscv: integer math	median 6ns  		lowest: 6ns     	highest: 9ns
               libriscv: fp math	median 12ns  		lowest: 12ns     	highest: 51ns
              libriscv: exp math	median 22ns  		lowest: 22ns     	highest: 53ns
               libriscv: fib(40)	median 66ns  		lowest: 65ns     	highest: 89ns
            libriscv: taylor(1K)	median 2234ns  		lowest: 2226ns     	highest: 2332ns
            luajit: integer math	median 52ns  		lowest: 49ns     	highest: 68ns
                 luajit: fp math	median 64ns  		lowest: 60ns     	highest: 82ns
                luajit: exp math	median 75ns  		lowest: 69ns     	highest: 92ns
                 luajit: fib(40)	median 66ns  		lowest: 63ns     	highest: 84ns
              luajit: taylor(1K)	median 858ns  		lowest: 826ns     	highest: 1006ns

       libriscv: complex syscall	median 50ns  		lowest: 48ns     	highest: 84ns
         luajit: complex syscall	median 873ns  		lowest: 858ns     	highest: 987ns

         libriscv: micro threads	median 102ns  		lowest: 99ns     	highest: 123ns
              luajit: coroutines	median 166ns  		lowest: 155ns     	highest: 199ns

     libriscv: micro thread args	median 127ns  		lowest: 125ns     	highest: 150ns
      libriscv: full thread args	median 139ns  		lowest: 136ns     	highest: 165ns
          luajit: coroutine args	median 206ns  		lowest: 198ns     	highest: 224ns
          luajit: coroutine args	median 249ns  		lowest: 237ns     	highest: 273ns

          libriscv: naive memcpy	median 586ns  		lowest: 532ns     	highest: 621ns
        libriscv: syscall memcpy	median 18ns  		lowest: 17ns     	highest: 21ns
                  luajit: memcpy	median 87ns  		lowest: 76ns     	highest: 104ns
        libriscv: syscall memset	median 15ns  		lowest: 15ns     	highest: 19ns
          libriscv: naive memset	median 188ns  		lowest: 181ns     	highest: 218ns
                  luajit: memset	median 67ns  		lowest: 64ns     	highest: 112ns

            libriscv: sieve(10M)	median 80ms  		lowest: 80ms     	highest: 80ms
              luajit: sieve(10M)	median 123ms  		lowest: 123ms     	highest: 123ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment