si rompe bungit add .
This commit is contained in:
parent
282a2d04d8
commit
f13ad2d2ce
2 changed files with 33 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
# Logs
|
||||
|
||||
meow
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
|
|
|
|||
47
index.js
47
index.js
|
|
@ -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 = '';
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
// Carica la libreria
|
||||
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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue