Skip to content

Instantly share code, notes, and snippets.

@fwsGonzo
Last active June 8, 2025 15:23
Show Gist options
  • Select an option

  • Save fwsGonzo/1af5b2a9b4f38c1f3d3074d78acdf609 to your computer and use it in GitHub Desktop.

Select an option

Save fwsGonzo/1af5b2a9b4f38c1f3d3074d78acdf609 to your computer and use it in GitHub Desktop.
Interpreted libriscv vs. 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 0x7cea3c63cd80 to virtual 0x10000 -> 0x417f3
* Program segment readable: 1 writable: 0 executable: 1
* Loading program of size 2096 from 0x7cea3c66e574 to virtual 0x427f4 -> 0x43024
* Program segment readable: 1 writable: 1 executable: 0
* Using program-provided exit function at 0x119c8
* Entry is at 0x10c20
libriscv: mips instr 1600020000, time 1.159662, 1379.729211 mip/s
libriscv: call overhead median 2ns lowest: 2ns highest: 2ns
libriscv: call args=1 median 2ns lowest: 2ns highest: 4ns
libriscv: call args=2 median 2ns lowest: 2ns highest: 4ns
libriscv: call args=3 median 2ns lowest: 2ns highest: 3ns
libriscv: call args=4 median 2ns lowest: 2ns highest: 2ns
libriscv: call args=5 median 2ns lowest: 2ns highest: 2ns
libriscv: call args=6 median 2ns lowest: 2ns highest: 4ns
libriscv: call args=7 median 2ns lowest: 2ns highest: 3ns
libriscv: call args=8 median 3ns lowest: 3ns highest: 3ns
libriscv: preempt overhead median 10ns lowest: 10ns highest: 12ns
libriscv: resume execution median 3ns lowest: 3ns highest: 3ns
luajit: call overhead median 150ns lowest: 149ns highest: 161ns
luajit: call args=1 median 161ns lowest: 159ns highest: 168ns
luajit: call args=2 median 164ns lowest: 162ns highest: 174ns
luajit: call args=3 median 166ns lowest: 165ns highest: 175ns
luajit: call args=4 median 170ns lowest: 165ns highest: 181ns
luajit: call args=5 median 173ns lowest: 171ns highest: 180ns
luajit: call args=6 median 178ns lowest: 176ns highest: 185ns
luajit: call args=7 median 180ns lowest: 178ns highest: 191ns
luajit: call args=8 median 184ns lowest: 181ns highest: 191ns
libriscv: syscall args=0 median 3ns lowest: 3ns highest: 3ns
libriscv: syscall args=1 median 3ns lowest: 3ns highest: 3ns
libriscv: syscall args=2 median 3ns lowest: 3ns highest: 6ns
libriscv: syscall args=3 median 3ns lowest: 3ns highest: 6ns
libriscv: syscall args=4 median 3ns lowest: 3ns highest: 5ns
libriscv: syscall args=5 median 3ns lowest: 3ns highest: 11ns
libriscv: syscall args=6 median 3ns lowest: 3ns highest: 3ns
libriscv: syscall args=7 median 3ns lowest: 3ns highest: 7ns
libriscv: syscall string median 6ns lowest: 6ns highest: 10ns
luajit: syscall args=0 median 168ns lowest: 164ns highest: 187ns
luajit: syscall args=1 median 183ns lowest: 180ns highest: 192ns
luajit: syscall args=2 median 195ns lowest: 192ns highest: 205ns
luajit: syscall args=3 median 207ns lowest: 204ns highest: 217ns
luajit: syscall args=4 median 221ns lowest: 218ns highest: 234ns
luajit: syscall args=5 median 234ns lowest: 229ns highest: 244ns
luajit: syscall args=6 median 247ns lowest: 243ns highest: 254ns
luajit: syscall args=7 median 260ns lowest: 256ns highest: 271ns
luajit: syscall string median 180ns lowest: 177ns highest: 188ns
After this point, call overhead is subtracted from every benchmark result for both libriscv and Lua
libriscv: array append median 3ns lowest: 3ns highest: 5ns
libriscv: vector append median 7ns lowest: 7ns highest: 11ns
luajit: table append median 22ns lowest: 18ns highest: 31ns
libriscv: 8x arguments median 28ns lowest: 27ns highest: 48ns
libriscv: 8x stored args median 33ns lowest: 30ns highest: 37ns
libriscv: 8x prepared args median 37ns lowest: 34ns highest: 43ns
luajit: 8x arguments median 374ns lowest: 366ns highest: 406ns
libriscv: integer math median 3ns lowest: 3ns highest: 6ns
libriscv: fp math median 8ns lowest: 8ns highest: 12ns
libriscv: exp math median 13ns lowest: 13ns highest: 25ns
libriscv: fib(40) median 156ns lowest: 148ns highest: 194ns
libriscv: taylor(1K) median 5889ns lowest: 5051ns highest: 6106ns
luajit: integer math median 49ns lowest: 46ns highest: 60ns
luajit: fp math median 59ns lowest: 56ns highest: 69ns
luajit: exp math median 67ns lowest: 64ns highest: 73ns
luajit: fib(40) median 60ns lowest: 57ns highest: 68ns
luajit: taylor(1K) median 858ns lowest: 844ns highest: 926ns
libriscv: complex syscall median 40ns lowest: 36ns highest: 46ns
luajit: complex syscall median 838ns lowest: 812ns highest: 853ns
libriscv: micro threads median 86ns lowest: 84ns highest: 93ns
luajit: coroutines median 167ns lowest: 159ns highest: 185ns
libriscv: micro thread args median 132ns lowest: 128ns highest: 139ns
libriscv: full thread args median 141ns lowest: 135ns highest: 149ns
luajit: coroutine args median 214ns lowest: 206ns highest: 225ns
luajit: coroutine args median 256ns lowest: 248ns highest: 271ns
libriscv: naive memcpy median 1052ns lowest: 944ns highest: 1186ns
libriscv: syscall memcpy median 19ns lowest: 18ns highest: 25ns
luajit: memcpy median 96ns lowest: 91ns highest: 109ns
libriscv: syscall memset median 11ns lowest: 11ns highest: 21ns
libriscv: naive memset median 169ns lowest: 163ns highest: 208ns
luajit: memset median 69ns lowest: 66ns highest: 80ns
libriscv: sieve(10M) median 133ms lowest: 133ms highest: 133ms
luajit: sieve(10M) median 131ms lowest: 131ms highest: 131ms
@fwsGonzo
Copy link
Author

fwsGonzo commented Jun 8, 2025

On my ThinkPad Z13 with AMD Ryzen 7 6860Z:

$ ./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 0x7e5b73c3c680 to virtual 0x10000 -> 0x417f3
* Program segment readable: 1 writable: 0  executable: 1
* Loading program of size 2096 from 0x7e5b73c6de74 to virtual 0x427f4 -> 0x43024
* Program segment readable: 1 writable: 1  executable: 0
* Using program-provided exit function at 0x119c8
* Entry is at 0x10c20
                  libriscv: mips	instr 1600020000, time 1.419230, 1127.386156 mip/s
         libriscv: call overhead	median 3ns  		lowest: 3ns     	highest: 7ns
           libriscv: call args=1	median 2ns  		lowest: 2ns     	highest: 8ns
           libriscv: call args=2	median 2ns  		lowest: 2ns     	highest: 3ns
           libriscv: call args=3	median 2ns  		lowest: 2ns     	highest: 2ns
           libriscv: call args=4	median 2ns  		lowest: 2ns     	highest: 3ns
           libriscv: call args=5	median 2ns  		lowest: 2ns     	highest: 6ns
           libriscv: call args=6	median 3ns  		lowest: 3ns     	highest: 7ns
           libriscv: call args=7	median 3ns  		lowest: 3ns     	highest: 7ns
           libriscv: call args=8	median 3ns  		lowest: 3ns     	highest: 6ns
      libriscv: preempt overhead	median 26ns  		lowest: 26ns     	highest: 34ns
      libriscv: resume execution	median 3ns  		lowest: 3ns     	highest: 5ns
           luajit: call overhead	median 196ns  		lowest: 193ns     	highest: 206ns
             luajit: call args=1	median 207ns  		lowest: 203ns     	highest: 226ns
             luajit: call args=2	median 219ns  		lowest: 215ns     	highest: 248ns
             luajit: call args=3	median 215ns  		lowest: 211ns     	highest: 232ns
             luajit: call args=4	median 262ns  		lowest: 219ns     	highest: 279ns
             luajit: call args=5	median 282ns  		lowest: 239ns     	highest: 315ns
             luajit: call args=6	median 284ns  		lowest: 240ns     	highest: 308ns
             luajit: call args=7	median 286ns  		lowest: 270ns     	highest: 368ns
             luajit: call args=8	median 293ns  		lowest: 254ns     	highest: 341ns

        libriscv: syscall args=0	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=1	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=2	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=3	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=4	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=5	median 4ns  		lowest: 4ns     	highest: 5ns
        libriscv: syscall args=6	median 4ns  		lowest: 4ns     	highest: 8ns
        libriscv: syscall args=7	median 4ns  		lowest: 4ns     	highest: 10ns
        libriscv: syscall string	median 7ns  		lowest: 7ns     	highest: 14ns
          luajit: syscall args=0	median 228ns  		lowest: 222ns     	highest: 239ns
          luajit: syscall args=1	median 244ns  		lowest: 238ns     	highest: 265ns
          luajit: syscall args=2	median 260ns  		lowest: 256ns     	highest: 293ns
          luajit: syscall args=3	median 279ns  		lowest: 272ns     	highest: 314ns
          luajit: syscall args=4	median 341ns  		lowest: 291ns     	highest: 574ns
          luajit: syscall args=5	median 371ns  		lowest: 314ns     	highest: 401ns
          luajit: syscall args=6	median 381ns  		lowest: 328ns     	highest: 406ns
          luajit: syscall args=7	median 394ns  		lowest: 363ns     	highest: 438ns
          luajit: syscall string	median 240ns  		lowest: 236ns     	highest: 258ns

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

          libriscv: array append	median 3ns  		lowest: 3ns     	highest: 7ns
         libriscv: vector append	median 8ns  		lowest: 8ns     	highest: 16ns
            luajit: table append	median 33ns  		lowest: 29ns     	highest: 59ns

          libriscv: 8x arguments	median 36ns  		lowest: 35ns     	highest: 45ns
        libriscv: 8x stored args	median 33ns  		lowest: 31ns     	highest: 46ns
      libriscv: 8x prepared args	median 41ns  		lowest: 39ns     	highest: 50ns
            luajit: 8x arguments	median 550ns  		lowest: 536ns     	highest: 663ns

          libriscv: integer math	median 3ns  		lowest: 3ns     	highest: 9ns
               libriscv: fp math	median 13ns  		lowest: 11ns     	highest: 21ns
              libriscv: exp math	median 14ns  		lowest: 14ns     	highest: 29ns
               libriscv: fib(40)	median 167ns  		lowest: 162ns     	highest: 181ns
            libriscv: taylor(1K)	median 7875ns  		lowest: 5260ns     	highest: 8937ns
            luajit: integer math	median 85ns  		lowest: 66ns     	highest: 107ns
                 luajit: fp math	median 148ns  		lowest: 90ns     	highest: 187ns
                luajit: exp math	median 152ns  		lowest: 130ns     	highest: 184ns
                 luajit: fib(40)	median 101ns  		lowest: 78ns     	highest: 168ns
              luajit: taylor(1K)	median 1038ns  		lowest: 1014ns     	highest: 1150ns

       libriscv: complex syscall	median 51ns  		lowest: 49ns     	highest: 77ns
         luajit: complex syscall	median 1100ns  		lowest: 1079ns     	highest: 1213ns

         libriscv: micro threads	median 107ns  		lowest: 104ns     	highest: 122ns
              luajit: coroutines	median 272ns  		lowest: 259ns     	highest: 338ns

     libriscv: micro thread args	median 163ns  		lowest: 159ns     	highest: 184ns
      libriscv: full thread args	median 176ns  		lowest: 173ns     	highest: 190ns
          luajit: coroutine args	median 354ns  		lowest: 337ns     	highest: 443ns
          luajit: coroutine args	median 462ns  		lowest: 435ns     	highest: 622ns

          libriscv: naive memcpy	median 1222ns  		lowest: 1155ns     	highest: 1393ns
        libriscv: syscall memcpy	median 22ns  		lowest: 21ns     	highest: 28ns
                  luajit: memcpy	median 117ns  		lowest: 109ns     	highest: 134ns
        libriscv: syscall memset	median 11ns  		lowest: 11ns     	highest: 16ns
          libriscv: naive memset	median 308ns  		lowest: 300ns     	highest: 443ns
                  luajit: memset	median 85ns  		lowest: 78ns     	highest: 143ns

            libriscv: sieve(10M)	median 225ms  		lowest: 225ms     	highest: 225ms
              luajit: sieve(10M)	median 241ms  		lowest: 241ms     	highest: 241ms

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