Skip to content

Instantly share code, notes, and snippets.

@fwsGonzo
Last active December 19, 2024 09:21
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 0x1020C
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 14772 from 0x5fdf5935c9c0 to virtual 0x10000 -> 0x139b4
* Program segment readable: 1 writable: 0 executable: 1
* Loading program of size 36 from 0x5fdf59360374 to virtual 0x149b4 -> 0x149d8
* Program segment readable: 1 writable: 1 executable: 0
* Using program-provided exit function at 0x12dbc
libriscv: Found embedded translation for hash 46CFA72F, 3/380 mappings
* Entry is at 0x1020c
libriscv: mips instr 0, time 0.060292, 0.000000 mip/s
libriscv: call overhead median 3ns lowest: 3ns highest: 6ns
libriscv: call args=1 median 7ns lowest: 7ns highest: 16ns
libriscv: call args=2 median 7ns lowest: 7ns highest: 24ns
libriscv: call args=3 median 7ns lowest: 7ns highest: 32ns
libriscv: call args=4 median 7ns lowest: 7ns highest: 15ns
libriscv: call args=5 median 7ns lowest: 7ns highest: 10ns
libriscv: call args=6 median 7ns lowest: 7ns highest: 10ns
libriscv: call args=7 median 7ns lowest: 7ns highest: 23ns
libriscv: call args=8 median 7ns lowest: 7ns highest: 11ns
libriscv: timed call overhead median 214ns lowest: 213ns highest: 232ns
libriscv: preempt overhead median 17ns lowest: 11ns highest: 21ns
libriscv: fork median 235ns lowest: 228ns highest: 257ns
libriscv: resume execution median 4ns lowest: 4ns highest: 7ns
luajit: call overhead median 131ns lowest: 129ns highest: 147ns
luajit: call args=1 median 146ns lowest: 144ns highest: 171ns
luajit: call args=2 median 149ns lowest: 147ns highest: 165ns
luajit: call args=3 median 153ns lowest: 151ns highest: 171ns
luajit: call args=4 median 156ns lowest: 154ns highest: 169ns
luajit: call args=5 median 159ns lowest: 158ns highest: 178ns
luajit: call args=6 median 163ns lowest: 161ns highest: 181ns
luajit: call args=7 median 166ns lowest: 164ns highest: 182ns
luajit: call args=8 median 170ns lowest: 168ns highest: 186ns
libriscv: syscall args=0 median 8ns lowest: 8ns highest: 11ns
libriscv: syscall args=1 median 8ns lowest: 8ns highest: 35ns
libriscv: syscall args=2 median 8ns lowest: 8ns highest: 9ns
libriscv: syscall args=3 median 8ns lowest: 8ns highest: 23ns
libriscv: syscall args=4 median 8ns lowest: 8ns highest: 9ns
libriscv: syscall args=5 median 8ns lowest: 8ns highest: 30ns
libriscv: syscall args=6 median 8ns lowest: 8ns highest: 9ns
libriscv: syscall args=7 median 8ns lowest: 8ns highest: 11ns
libriscv: syscall string median 10ns lowest: 9ns highest: 12ns
luajit: syscall args=0 median 146ns lowest: 145ns highest: 163ns
luajit: syscall args=1 median 159ns lowest: 157ns highest: 180ns
luajit: syscall args=2 median 170ns lowest: 168ns highest: 185ns
luajit: syscall args=3 median 184ns lowest: 180ns highest: 200ns
luajit: syscall args=4 median 194ns lowest: 191ns highest: 216ns
luajit: syscall args=5 median 204ns lowest: 202ns highest: 216ns
luajit: syscall args=6 median 220ns lowest: 214ns highest: 235ns
luajit: syscall args=7 median 229ns lowest: 224ns highest: 247ns
luajit: syscall string median 161ns lowest: 159ns highest: 173ns
After this point, call overhead is subtracted from every benchmark result for both libriscv and Lua
libriscv: array append median 4ns lowest: 4ns highest: 12ns
libriscv: vector append median 5ns lowest: 5ns highest: 7ns
luajit: table append median 31ns lowest: 19ns highest: 53ns
libriscv: 8x arguments median 21ns lowest: 21ns highest: 47ns
libriscv: 8x stored args median 16ns lowest: 16ns highest: 41ns
libriscv: 8x prepared args median 20ns lowest: 20ns highest: 37ns
luajit: 8x arguments median 317ns lowest: 309ns highest: 349ns
libriscv: integer math median 5ns lowest: 5ns highest: 5ns
libriscv: fp math median 7ns lowest: 7ns highest: 8ns
libriscv: exp math median 9ns lowest: 9ns highest: 24ns
libriscv: fib(40) median 3ns lowest: 3ns highest: 24ns
libriscv: taylor(1K) median 664ns lowest: 635ns highest: 692ns
luajit: integer math median 42ns lowest: 38ns highest: 53ns
luajit: fp math median 52ns lowest: 51ns highest: 67ns
luajit: exp math median 57ns lowest: 56ns highest: 87ns
luajit: fib(40) median 53ns lowest: 51ns highest: 73ns
luajit: taylor(1K) median 943ns lowest: 889ns highest: 964ns
libriscv: complex syscall median 33ns lowest: 32ns highest: 71ns
luajit: complex syscall median 726ns lowest: 719ns highest: 791ns
libriscv: micro threads median 164ns lowest: 150ns highest: 197ns
luajit: coroutines median 166ns lowest: 160ns highest: 199ns
libriscv: micro thread args median 190ns lowest: 173ns highest: 231ns
libriscv: full thread args median 192ns lowest: 180ns highest: 209ns
luajit: coroutine args median 223ns lowest: 217ns highest: 243ns
luajit: coroutine args median 238ns lowest: 231ns highest: 261ns
libriscv: naive memcpy median 524ns lowest: 429ns highest: 627ns
libriscv: syscall memcpy median 13ns lowest: 13ns highest: 16ns
luajit: memcpy median 97ns lowest: 90ns highest: 129ns
libriscv: syscall memset median 9ns lowest: 8ns highest: 31ns
libriscv: naive memset median 57ns lowest: 56ns highest: 79ns
luajit: memset median 65ns lowest: 63ns highest: 202ns
libriscv: sieve(10M) median 38ms lowest: 38ms highest: 38ms
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

* All benchmark results are measured in 200x1200 samples
              benchmark overhead	median 0ns  		lowest: 0ns     	highest: 0ns
Self-test running ELF entry at 0x1021C
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
                  libriscv: mips	instr 1600025000, time 0.649474, 2463.571541 mip/s
         libriscv: call overhead	median 4ns  		lowest: 4ns     	highest: 4ns
      libriscv: preempt overhead	median 14ns  		lowest: 14ns     	highest: 19ns
                  libriscv: fork	median 235ns  		lowest: 220ns     	highest: 258ns
      libriscv: resume execution	median 3ns  		lowest: 3ns     	highest: 3ns
           luajit: call overhead	median 133ns  		lowest: 132ns     	highest: 155ns

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

          libriscv: array append	median 5ns  		lowest: 4ns     	highest: 7ns
         libriscv: vector append	median 9ns  		lowest: 9ns     	highest: 18ns
            luajit: table append	median 31ns  		lowest: 20ns     	highest: 70ns

          libriscv: 8x arguments	median 41ns  		lowest: 37ns     	highest: 48ns
        libriscv: 8x stored args	median 28ns  		lowest: 27ns     	highest: 39ns
      libriscv: 8x prepared args	median 41ns  		lowest: 38ns     	highest: 56ns
            luajit: 8x arguments	median 333ns  		lowest: 326ns     	highest: 432ns

          libriscv: integer math	median 6ns  		lowest: 5ns     	highest: 8ns
               libriscv: fp math	median 25ns  		lowest: 24ns     	highest: 35ns
              libriscv: exp math	median 22ns  		lowest: 21ns     	highest: 30ns
               libriscv: fib(40)	median 83ns  		lowest: 81ns     	highest: 91ns
            libriscv: taylor(1K)	median 2606ns  		lowest: 2579ns     	highest: 2770ns
            luajit: integer math	median 48ns  		lowest: 47ns     	highest: 94ns
                 luajit: fp math	median 60ns  		lowest: 58ns     	highest: 104ns
                luajit: exp math	median 66ns  		lowest: 64ns     	highest: 75ns
                 luajit: fib(40)	median 61ns  		lowest: 59ns     	highest: 77ns
              luajit: taylor(1K)	median 967ns  		lowest: 908ns     	highest: 982ns

      libriscv: syscall overhead	median 1ns  		lowest: 1ns     	highest: 3ns
        libriscv: syscall string	median 9ns  		lowest: 8ns     	highest: 13ns
        luajit: syscall overhead	median 13ns  		lowest: 12ns     	highest: 62ns
          luajit: syscall string	median 32ns  		lowest: 31ns     	highest: 50ns

       libriscv: complex syscall	median 73ns  		lowest: 69ns     	highest: 110ns
         luajit: complex syscall	median 785ns  		lowest: 765ns     	highest: 860ns

         libriscv: micro threads	median 146ns  		lowest: 138ns     	highest: 201ns
              luajit: coroutines	median 184ns  		lowest: 181ns     	highest: 210ns

     libriscv: micro thread args	median 224ns  		lowest: 211ns     	highest: 273ns
      libriscv: full thread args	median 222ns  		lowest: 214ns     	highest: 265ns
          luajit: coroutine args	median 236ns  		lowest: 220ns     	highest: 285ns
          luajit: coroutine args	median 257ns  		lowest: 250ns     	highest: 280ns

          libriscv: naive memcpy	median 308ns  		lowest: 305ns     	highest: 388ns
        libriscv: syscall memcpy	median 25ns  		lowest: 24ns     	highest: 38ns
                  luajit: memcpy	median 99ns  		lowest: 92ns     	highest: 112ns
        libriscv: syscall memset	median 15ns  		lowest: 14ns     	highest: 25ns
          libriscv: naive memset	median 162ns  		lowest: 157ns     	highest: 184ns
                  luajit: memset	median 70ns  		lowest: 68ns     	highest: 78ns

            libriscv: sieve(10M)	median 94ms  		lowest: 94ms     	highest: 94ms
PANIC: unprotected error in call to Lua API (not enough memory)

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