Skip to content

Commit

Permalink
example: add allocations example for benchmarking kernel changes (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored Sep 19, 2024
1 parent 96aa0ed commit a83d9eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/allocations/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WASI_SDK_PATH?=../../wasi-sdk

.PHONY: allocations
allocations:
$(WASI_SDK_PATH)/bin/clang -target wasm32-unknown-unknown -nostdlib -Wl,--no-entry -Wl,--export=allocations -O2 -g -o allocations.wasm allocations.c

run: allocations
extism call ./allocations.wasm allocations --loop 100 --wasi
16 changes: 16 additions & 0 deletions examples/allocations/allocations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define EXTISM_IMPLEMENTATION
#include "../../extism-pdk.h"

uint64_t count = 0;

int32_t EXTISM_EXPORTED_FUNCTION(allocations) {

for (int i = 0; i < 10000; i++) {
ExtismHandle h = extism_alloc(i + 10);
if (i % 3 == 0) {
extism_free(h);
}
}

return 0;
}

0 comments on commit a83d9eb

Please sign in to comment.