Skip to content

Instantly share code, notes, and snippets.

@fwsGonzo
Last active June 8, 2025 13:35
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 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 0x771f2b24b0c0 to virtual 0x10000 -> 0x417f3
* Program segment readable: 1 writable: 0  executable: 1
* Loading program of size 2096 from 0x771f2b27c8b4 to virtual 0x427f4 -> 0x43024
* Program segment readable: 1 writable: 1  executable: 0
* Using program-provided exit function at 0x119c8
libriscv: No embedded translation found for hash 9077D2DD
libriscv: Emitted 40285 accelerated instructions, 1 blocks and 5747 functions. GP=0x436C0
libriscv: Activated libtcc binary translation with 1/5747 mappings
* Entry is at 0x10c20
                  libriscv: mips	instr 1600020000, time 1.232285, 1298.417522 mip/s
         libriscv: call overhead	median 2ns  		lowest: 2ns     	highest: 4ns
           libriscv: call args=1	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=2	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=3	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=4	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=5	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=6	median 17ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=7	median 18ns  		lowest: 17ns     	highest: 21ns
           libriscv: call args=8	median 18ns  		lowest: 18ns     	highest: 22ns
      libriscv: preempt overhead	median 10ns  		lowest: 10ns     	highest: 21ns
      libriscv: resume execution	median 16ns  		lowest: 16ns     	highest: 22ns
           luajit: call overhead	median 151ns  		lowest: 149ns     	highest: 163ns
             luajit: call args=1	median 162ns  		lowest: 159ns     	highest: 170ns
             luajit: call args=2	median 165ns  		lowest: 162ns     	highest: 174ns
             luajit: call args=3	median 169ns  		lowest: 166ns     	highest: 178ns
             luajit: call args=4	median 171ns  		lowest: 169ns     	highest: 178ns
             luajit: call args=5	median 174ns  		lowest: 171ns     	highest: 182ns
             luajit: call args=6	median 178ns  		lowest: 175ns     	highest: 193ns
             luajit: call args=7	median 181ns  		lowest: 178ns     	highest: 193ns
             luajit: call args=8	median 183ns  		lowest: 180ns     	highest: 193ns

        libriscv: syscall args=0	median 27ns  		lowest: 27ns     	highest: 31ns
        libriscv: syscall args=1	median 27ns  		lowest: 27ns     	highest: 31ns
        libriscv: syscall args=2	median 29ns  		lowest: 28ns     	highest: 34ns
        libriscv: syscall args=3	median 29ns  		lowest: 28ns     	highest: 34ns
        libriscv: syscall args=4	median 28ns  		lowest: 27ns     	highest: 31ns
        libriscv: syscall args=5	median 27ns  		lowest: 27ns     	highest: 30ns
        libriscv: syscall args=6	median 28ns  		lowest: 27ns     	highest: 32ns
        libriscv: syscall args=7	median 29ns  		lowest: 28ns     	highest: 45ns
        libriscv: syscall string	median 29ns  		lowest: 28ns     	highest: 37ns
          luajit: syscall args=0	median 167ns  		lowest: 164ns     	highest: 185ns
          luajit: syscall args=1	median 182ns  		lowest: 178ns     	highest: 188ns
          luajit: syscall args=2	median 195ns  		lowest: 191ns     	highest: 205ns
          luajit: syscall args=3	median 208ns  		lowest: 204ns     	highest: 217ns
          luajit: syscall args=4	median 220ns  		lowest: 216ns     	highest: 228ns
          luajit: syscall args=5	median 233ns  		lowest: 229ns     	highest: 241ns
          luajit: syscall args=6	median 247ns  		lowest: 242ns     	highest: 260ns
          luajit: syscall args=7	median 261ns  		lowest: 255ns     	highest: 272ns
          luajit: syscall string	median 178ns  		lowest: 175ns     	highest: 186ns

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

          libriscv: array append	median 16ns  		lowest: 16ns     	highest: 20ns
         libriscv: vector append	median 18ns  		lowest: 18ns     	highest: 25ns
            luajit: table append	median 25ns  		lowest: 17ns     	highest: 40ns

          libriscv: 8x arguments	median 43ns  		lowest: 43ns     	highest: 51ns
        libriscv: 8x stored args	median 39ns  		lowest: 38ns     	highest: 52ns
      libriscv: 8x prepared args	median 45ns  		lowest: 44ns     	highest: 58ns
            luajit: 8x arguments	median 370ns  		lowest: 363ns     	highest: 386ns

          libriscv: integer math	median 16ns  		lowest: 16ns     	highest: 19ns
               libriscv: fp math	median 29ns  		lowest: 29ns     	highest: 34ns
              libriscv: exp math	median 49ns  		lowest: 47ns     	highest: 56ns
               libriscv: fib(40)	median 43ns  		lowest: 43ns     	highest: 47ns
            libriscv: taylor(1K)	median 2221ns  		lowest: 2207ns     	highest: 2230ns
            luajit: integer math	median 47ns  		lowest: 45ns     	highest: 58ns
                 luajit: fp math	median 60ns  		lowest: 55ns     	highest: 72ns
                luajit: exp math	median 67ns  		lowest: 62ns     	highest: 74ns
                 luajit: fib(40)	median 60ns  		lowest: 57ns     	highest: 68ns
              luajit: taylor(1K)	median 907ns  		lowest: 851ns     	highest: 926ns

       libriscv: complex syscall	median 129ns  		lowest: 124ns     	highest: 139ns
         luajit: complex syscall	median 852ns  		lowest: 813ns     	highest: 872ns

         libriscv: micro threads	median 141ns  		lowest: 138ns     	highest: 147ns
              luajit: coroutines	median 163ns  		lowest: 155ns     	highest: 180ns

     libriscv: micro thread args	median 212ns  		lowest: 206ns     	highest: 221ns
      libriscv: full thread args	median 199ns  		lowest: 194ns     	highest: 212ns
          luajit: coroutine args	median 208ns  		lowest: 200ns     	highest: 230ns
          luajit: coroutine args	median 253ns  		lowest: 246ns     	highest: 274ns

          libriscv: naive memcpy	median 1081ns  		lowest: 954ns     	highest: 1137ns
        libriscv: syscall memcpy	median 48ns  		lowest: 46ns     	highest: 53ns
                  luajit: memcpy	median 94ns  		lowest: 85ns     	highest: 105ns
        libriscv: syscall memset	median 40ns  		lowest: 40ns     	highest: 46ns
          libriscv: naive memset	median 246ns  		lowest: 192ns     	highest: 269ns
                  luajit: memset	median 68ns  		lowest: 64ns     	highest: 84ns

            libriscv: sieve(10M)	median 47ms  		lowest: 47ms     	highest: 47ms
              luajit: sieve(10M)	median 135ms  		lowest: 135ms     	highest: 135ms

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