si rompe bungit add .

This commit is contained in:
PanSi21 2025-01-05 01:13:04 +01:00
parent 282a2d04d8
commit f13ad2d2ce
Signed by untrusted user who does not match committer: PanSi21
GPG key ID: 755F8874C65EF462
2 changed files with 33 additions and 15 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
# Logs
meow
logs
_.log
npm-debug.log_

View file

@ -1,27 +1,44 @@
import { dlopen, FFIType } from "bun:ffi";
const path = `./libtesticolo.so`;
// Funzione JavaScript equivalente
function jsTest() {
let c = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
let j = '';
let h = '';
// Carica la libreria
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: [FFIType.pointer, FFIType.pointer], // Usato pointer per i buffer
returns: FFIType.void,
args: [], // La funzione C non prende argomenti
returns: FFIType.int, // La funzione C restituisce un intero
},
});
const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
// Funzione per il test in C
function cTest() {
const start = performance.now();
// Converti la stringa in un buffer (Uint8Array)
const inputBuffer = new TextEncoder().encode(input);
// Chiama la funzione C per eseguire il test
symbols.testicolo();
// Crea un buffer di output della stessa dimensione
const outputBuffer = new ArrayBuffer(inputBuffer.length);
const end = performance.now();
console.log(`C Execution Time: ${end - start}ms`);
}
// Passa i buffer alla funzione C
symbols.testicolo(inputBuffer, outputBuffer);
// Decodifica l'output dal buffer
const result = new TextDecoder().decode(new Uint8Array(outputBuffer));
console.log(result);
// Avvia i test
jsTest();
cTest();