Git Product home page Git Product logo

dynamic-function-benchmark's Introduction

JIT (FFI) vs PLT benchmark

This is a simple benchmark for demonstrating the PLT function call overhead. It requires x86-64, but will otherwise work on any POSIX system.

Full article: When FFI Function Calls Beat Native C

Results on an Intel i7-6700 (Skylake):

jit: 1.008108 ns/call
plt: 1.759799 ns/call
ind: 1.257125 ns/call

This is the assembly used for JIT benchmark:

check:  dd 0

jit_benchmark:
	push  rbx
	xor   ebx, ebx
.loop:	mov   eax, [rel check]
	test  eax, eax
	je    .done
	call  empty
	inc   ebx
	jmp   .loop
.done:	mov   eax, ebx
	pop   rbx
	ret

The relative address for empty is patched in by the JIT compiler.

dynamic-function-benchmark's People

Contributors

brisad avatar djhenderson avatar skeeto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dynamic-function-benchmark's Issues

segfault on cygwin

benchmark compiles as is on cygwin, but generates a segment fault while trying to perform the jit benchmark. gdb was no help, but I observed that the compilation warned about redefining PAGESIZE from 65536 to 4096. The attached included patch compensates for this, and allows the benchmark to execute successfully giving these result on my laptop with "Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, 2808 Mhz, 4 Core(s), 8 Logical Processor(s)".

$ ./benchmark
jit: 2.447226 ns/call
plt: 2.003026 ns/call
ind: 1.725051 ns/call

benchmark.c.patch

--- a/benchmark.c
+++ b/benchmark.c
@@ -9,9 +9,11 @@
 #include <unistd.h>
 #include <sys/mman.h>

-#define PAGESIZE           4096
-#define PAGEMASK           (~0xfff)
-#define SAFETY_MARGIN      (1024 * PAGESIZE)
+#if !defined(PAGESIZE)
+    #define PAGESIZE       4096
+#endif
+#define PAGEMASK           (~(PAGESIZE-1))
+#define SAFETY_MARGIN      (1024 * 1024 * 4)
 #define BENCHMARK_SECONDS  2
 #define BENCHMARK_SAMPLES  4

(Note: one blank line at end of patch.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.