BUN-test/index.js
2025-01-05 01:13:04 +01:00

44 lines
968 B
JavaScript

import { dlopen, FFIType } from "bun:ffi";
// Funzione JavaScript equivalente
function jsTest() {
let c = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
let j = '';
let h = '';
const start = performance.now();
for (let a = 0; a < 1000; a++) {
h = c.toUpperCase();
j = h.toLowerCase();
c = j;
}
const end = performance.now();
console.log(`JavaScript Execution Time: ${end - start}ms`);
}
// Carica la libreria C
const path = `./libtesticolo.so`;
const { symbols } = dlopen(path, {
testicolo: {
args: [], // La funzione C non prende argomenti
returns: FFIType.int, // La funzione C restituisce un intero
},
});
// Funzione per il test in C
function cTest() {
const start = performance.now();
// Chiama la funzione C per eseguire il test
symbols.testicolo();
const end = performance.now();
console.log(`C Execution Time: ${end - start}ms`);
}
// Avvia i test
jsTest();
cTest();