This commit is contained in:
Brooke Vibber 2025-12-23 10:51:01 -08:00
commit 7a6e4b31bd
10 changed files with 989 additions and 0 deletions

19
arg-test/Makefile Normal file
View file

@ -0,0 +1,19 @@
.FAKE : all clean test
all: argy.wasm argy.wat
argy.wat : argy.wasm
"$(HOME)/src/emsdk/upstream/bin/wasm-dis" argy.wasm | tee argy.wat
argy.wasm : argy.js
argy.js : argy.c
emcc -O1 -sMODULARIZE -s'EXPORTED_FUNCTIONS=["_main","_bench_one","_bench_two","_bench_three","_bench_four","_bench_five","_bench_six","_bench_seven","_bench_eight"]' -o argy.js argy.c
clean:
rm -f argy.js
rm -f argy.wasm
rm -f argy.wat
test: argy.js argy.wasm
node test-argy.js

100
arg-test/argy.c Normal file
View file

@ -0,0 +1,100 @@
#include <inttypes.h>
static int64_t accumulator = 0;
#define ITERS 1000000000
int64_t reset(int64_t val) {
int64_t temp = accumulator;
accumulator = val;
return temp;
}
__attribute__((noinline)) int64_t one(int64_t a) {
accumulator += a;
return accumulator;
}
__attribute__((noinline)) int64_t two(int64_t a, int64_t b) {
accumulator += a;
accumulator += b;
return accumulator;
}
__attribute__((noinline)) int64_t three(int64_t a, int64_t b, int64_t c) {
accumulator += a;
accumulator += b;
accumulator += c;
return accumulator;
}
__attribute__((noinline)) int64_t four(int64_t a, int64_t b, int64_t c, int64_t d) {
accumulator += a;
accumulator += b;
accumulator += c;
accumulator += d;
return accumulator;
}
__attribute__((noinline)) int64_t five(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e) {
accumulator += a;
accumulator += b;
accumulator += c;
accumulator += d;
accumulator += e;
return accumulator;
}
__attribute__((noinline)) int64_t six(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f) {
accumulator += a;
accumulator += b;
accumulator += c;
accumulator += d;
accumulator += e;
accumulator += f;
return accumulator;
}
__attribute__((noinline)) int64_t seven(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f, int64_t g) {
accumulator += a;
accumulator += b;
accumulator += c;
accumulator += d;
accumulator += e;
accumulator += f;
accumulator += g;
return accumulator;
}
__attribute__((noinline)) int64_t eight(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f, int64_t g, int64_t h) {
accumulator += a;
accumulator += b;
accumulator += c;
accumulator += d;
accumulator += e;
accumulator += f;
accumulator += g;
accumulator += h;
return accumulator;
}
#define BENCH(func, args) \
int64_t bench_##func(void) { \
for (int64_t i = 0; i < ITERS; i++) { \
func args; \
} \
return accumulator; \
}
BENCH(one, (accumulator))
BENCH(two, (accumulator, accumulator + 1))
BENCH(three, (accumulator, accumulator + 1, accumulator + 2))
BENCH(four, (accumulator, accumulator + 1, accumulator + 2, accumulator + 3))
BENCH(five, (accumulator, accumulator + 1, accumulator + 2, accumulator + 3, accumulator + 4))
BENCH(six, (accumulator, accumulator + 1, accumulator + 2, accumulator + 3, accumulator + 4, accumulator + 5))
BENCH(seven, (accumulator, accumulator + 1, accumulator + 2, accumulator + 3, accumulator + 4, accumulator + 5, accumulator + 6))
BENCH(eight, (accumulator, accumulator + 1, accumulator + 2, accumulator + 3, accumulator + 4, accumulator + 5, accumulator + 6, accumulator + 7))
int main(int argc, const char **argv) {
return 0;
}

21
arg-test/test-argy.js Normal file
View file

@ -0,0 +1,21 @@
const Module = require('./argy.js');
Module().then((module) => {
const benches = [
'_bench_one',
'_bench_two',
'_bench_three',
'_bench_four',
'_bench_five',
'_bench_six',
'_bench_seven',
'_bench_eight'
];
for (const bench of benches) {
console.log(bench);
const start = performance.now();
module[bench]();
const delta = performance.now() - start;
console.log(`${delta} ms`);
}
});