Skip to content

Commit

Permalink
Added simple benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
yugr committed Jan 26, 2025
1 parent 916fe17 commit 9b12cb7
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/benchmark/interposed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2025 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#include "interposed.h"

__attribute__((visibility("default")))
void foo() {}
15 changes: 15 additions & 0 deletions tests/benchmark/interposed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2025 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#ifndef INTERPOSED_H
#define INTERPOSED_H

extern void foo();

#endif
23 changes: 23 additions & 0 deletions tests/benchmark/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2025 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#include "interposed.h"

#define NITER 1000000000L

int main() {
for (long i = 0; i < NITER; ++i)
#ifdef BASELINE
asm volatile("");
#else
foo();
#endif

return 0;
}
61 changes: 61 additions & 0 deletions tests/benchmark/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

# Copyright 2025 Yury Gribov
#
# The MIT License (MIT)
#
# Use of this source code is governed by MIT license that can be
# found in the LICENSE.txt file.

# This is a simple benchmark of Implib's overhead.
#
# On my machine results are very close, Implib being 0.5-1% slower.

set -eu

cd $(dirname $0)

if test -n "${1:-}"; then
ARCH="$1"
fi

. ../common.sh

CFLAGS="-g -O2 $CFLAGS"
N=10

# Need sudo for nice...
RUN='nice -n -20 taskset 1'

$CC $CFLAGS -shared -fPIC interposed.c -o libinterposed.so
${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so

export LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-}

# Baseline

$CC $CFLAGS -DBASELINE main.c

echo "Baseline:"
$RUN time ./a.out

# Normal

$CC $CFLAGS main.c -L. -linterposed $LIBS

echo "Normal:"
$RUN time ./a.out

# Implib

$CC $CFLAGS main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS

echo "Implib:"
$RUN time ./a.out

# Implib (IMPLIB_EXPORT_SHIMS)

$CC $CFLAGS -DIMPLIB_EXPORT_SHIMS -rdynamic main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS

echo "Implib (IMPLIB_EXPORT_SHIMS):"
$RUN time ./a.out

0 comments on commit 9b12cb7

Please sign in to comment.