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
|
# Logs
|
||||||
|
|
||||||
|
meow
|
||||||
logs
|
logs
|
||||||
_.log
|
_.log
|
||||||
npm-debug.log_
|
npm-debug.log_
|
||||||
|
|
|
||||||
47
index.js
47
index.js
|
|
@ -1,27 +1,44 @@
|
||||||
import { dlopen, FFIType } from "bun:ffi";
|
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, {
|
const { symbols } = dlopen(path, {
|
||||||
testicolo: {
|
testicolo: {
|
||||||
args: [FFIType.pointer, FFIType.pointer], // Usato pointer per i buffer
|
args: [], // La funzione C non prende argomenti
|
||||||
returns: FFIType.void,
|
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)
|
// Chiama la funzione C per eseguire il test
|
||||||
const inputBuffer = new TextEncoder().encode(input);
|
symbols.testicolo();
|
||||||
|
|
||||||
// Crea un buffer di output della stessa dimensione
|
const end = performance.now();
|
||||||
const outputBuffer = new ArrayBuffer(inputBuffer.length);
|
console.log(`C Execution Time: ${end - start}ms`);
|
||||||
|
}
|
||||||
|
|
||||||
// Passa i buffer alla funzione C
|
// Avvia i test
|
||||||
symbols.testicolo(inputBuffer, outputBuffer);
|
jsTest();
|
||||||
|
cTest();
|
||||||
// Decodifica l'output dal buffer
|
|
||||||
const result = new TextDecoder().decode(new Uint8Array(outputBuffer));
|
|
||||||
console.log(result);
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue