Skip to content

Instantly share code, notes, and snippets.

@fwsGonzo
Last active June 15, 2024 21:02
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 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.078446, 20396.605283 mip/s
libriscv: call overhead median 3ns lowest: 3ns highest: 3ns
libriscv: preempt overhead median 12ns lowest: 11ns highest: 15ns
libriscv: fork median 221ns lowest: 215ns highest: 353ns
libriscv: resume execution median 4ns lowest: 4ns highest: 9ns
luajit: call overhead median 126ns lowest: 126ns highest: 195ns
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 1ns lowest: 1ns highest: 4ns
luajit: table append median 33ns lowest: 24ns highest: 157ns
libriscv: 8x arguments median 18ns lowest: 18ns highest: 51ns
libriscv: 8x stored args median 14ns lowest: 13ns highest: 15ns
libriscv: 8x prepared args median 18ns lowest: 18ns highest: 26ns
luajit: 8x arguments median 319ns lowest: 315ns highest: 434ns
libriscv: integer math median 1ns lowest: 1ns highest: 4ns
libriscv: fp math median 4ns lowest: 4ns highest: 10ns
libriscv: exp math median 11ns lowest: 11ns highest: 14ns
libriscv: fib(40) median 10ns lowest: 10ns highest: 13ns
libriscv: taylor(1K) median 632ns lowest: 599ns highest: 758ns
luajit: integer math median 45ns lowest: 38ns highest: 102ns
luajit: fp math median 55ns lowest: 51ns highest: 99ns
luajit: exp math median 60ns lowest: 58ns highest: 169ns
luajit: fib(40) median 56ns lowest: 53ns highest: 118ns
luajit: taylor(1K) median 896ns lowest: 837ns highest: 981ns
libriscv: syscall overhead median 2ns lowest: 2ns highest: 4ns
libriscv: syscall string median 4ns lowest: 3ns highest: 7ns
luajit: syscall overhead median 14ns lowest: 13ns highest: 48ns
luajit: syscall string median 29ns lowest: 28ns highest: 86ns
libriscv: complex syscall median 30ns lowest: 30ns highest: 76ns
luajit: complex syscall median 737ns lowest: 725ns highest: 803ns
libriscv: micro threads median 128ns lowest: 125ns highest: 195ns
luajit: coroutines median 165ns lowest: 161ns highest: 245ns
libriscv: micro thread args median 156ns lowest: 152ns highest: 212ns
libriscv: full thread args median 168ns lowest: 163ns highest: 217ns
luajit: coroutine args median 216ns lowest: 212ns highest: 268ns
luajit: coroutine args median 237ns lowest: 234ns highest: 293ns
libriscv: naive memcpy median 60ns lowest: 60ns highest: 98ns
libriscv: syscall memcpy median 18ns lowest: 17ns highest: 28ns
luajit: memcpy median 97ns lowest: 89ns highest: 192ns
libriscv: syscall memset median 8ns lowest: 8ns highest: 12ns
libriscv: naive memset median 34ns lowest: 34ns highest: 63ns
luajit: memset median 69ns lowest: 68ns highest: 182ns
libriscv: sieve(10M) median 32ms lowest: 32ms highest: 32ms
luajit: sieve(10M) median 125ms lowest: 125ms highest: 125ms
@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