infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
903_generation_benchmark.c File Reference

A micro-benchmark to measure the performance of trampoline generation. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
#include <time.h>
Include dependency graph for 903_generation_benchmark.c:

Macros

#define DBLTAP_IMPLEMENTATION
 
#define BENCHMARK_ITERATIONS   10000
 

Functions

void benchmark_handler (Point p)
 A dummy handler function to provide a valid function pointer for creation.
 
 diag ("Trampoline Generation Benchmark")
 
 diag ("Iterations: %d", BENCHMARK_ITERATIONS)
 
 diag ("Target: Full create/destroy cycle for a reverse callback with signature 'void(Point)'")
 
 for (int i=0;i< BENCHMARK_ITERATIONS;++i)
 
 diag ("Total time: %.4f s", total_time)
 
 diag ("Average generation time: %.2f us/op", time_per_generation_us)
 
 pass ("Benchmark completed successfully.")
 

Variables

 TEST
 
clock_t start = clock()
 
clock_t end = clock()
 
double total_time = ((double)(end - start)) / CLOCKS_PER_SEC
 
double time_per_generation_us = (total_time / BENCHMARK_ITERATIONS) * 1e6
 

Detailed Description

A micro-benchmark to measure the performance of trampoline generation.

This is not a correctness test, but a performance benchmark. Its purpose is to measure the time it takes to perform a complete create/destroy cycle for a reverse trampoline. This is a key metric for applications that need to create callbacks dynamically and frequently.

The benchmark runs a tight loop that, in each iteration:

  1. Creates a memory arena.
  2. Programmatically creates a moderately complex infix_type for a struct.
  3. Calls infix_reverse_create_callback_manual to generate a JIT-compiled callback.
  4. Destroys the created trampoline.
  5. Destroys the arena.

The output is the average time for one complete cycle, reported in microseconds per operation (us/op). This metric is useful for tracking the performance of the entire JIT pipeline, including type creation, ABI classification, code emission, and memory management.

Macro Definition Documentation

◆ BENCHMARK_ITERATIONS

#define BENCHMARK_ITERATIONS   10000

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ benchmark_handler()

void benchmark_handler ( Point  p)

A dummy handler function to provide a valid function pointer for creation.

◆ diag() [1/5]

diag ( "Average generation time: %.2f us/op"  ,
time_per_generation_us   
)

◆ diag() [2/5]

diag ( "Iterations: %d"  ,
BENCHMARK_ITERATIONS   
)

◆ diag() [3/5]

diag ( "Target: Full create/destroy cycle for a reverse callback with signature 'void(Point)'"  )

◆ diag() [4/5]

diag ( "Total time: %.4f s"  ,
total_time   
)

◆ diag() [5/5]

diag ( "Trampoline Generation Benchmark"  )

◆ for()

for ( )

◆ pass()

pass ( "Benchmark completed successfully."  )

Variable Documentation

◆ end

clock_t end = clock()

◆ start

clock_t start = clock()

◆ TEST

TEST
Initial value:
{
plan(1)
#define plan(count)
Definition double_tap.h:163

◆ time_per_generation_us

double time_per_generation_us = (total_time / BENCHMARK_ITERATIONS) * 1e6

◆ total_time

double total_time = ((double)(end - start)) / CLOCKS_PER_SEC