Files
performance-tests/wasm_add_pthread.c

43 lines
1.0 KiB
C
Raw Normal View History

2025-11-18 12:55:09 +01:00
#include <stdlib.h>
#include <stdio.h>
#include <emscripten/emscripten.h> // For EMSCRIPTEN_KEEPALIVE
#define ARRAY_SIZE 15000576 // 15 million items (still define for context, but not used directly in loops anymore)
EMSCRIPTEN_KEEPALIVE
int* alloc( int size ) {
return ( int * ) malloc( size );
}
EMSCRIPTEN_KEEPALIVE
void dealloc( int * ptr, int size ) {
free( ptr );
}
EMSCRIPTEN_KEEPALIVE
float* alloc_float_array(int size) {
return ( float * ) malloc(size * sizeof(float));
}
EMSCRIPTEN_KEEPALIVE
void dealloc_float_array(float* ptr) {
free(ptr);
}
// Modified init_arrays to operate on a specific range
EMSCRIPTEN_KEEPALIVE
void init_arrays_range(float* a, float* b, int start_idx, int end_idx) {
for (int i = start_idx; i < end_idx; i++) {
a[i] = (float)i;
b[i] = (float)i * 2.0f;
}
}
// Modified calculate to operate on a specific range
EMSCRIPTEN_KEEPALIVE
void calculate_range(float* a, float* b, float* c, int start_idx, int end_idx) {
for (int i = start_idx; i < end_idx; i++) {
c[i] = a[i] + b[i];
}
}