This commit is contained in:
PanSi21 2025-01-05 18:18:37 +01:00
parent 4992ad603e
commit 53528bc35e
Signed by untrusted user who does not match committer: PanSi21
GPG key ID: 755F8874C65EF462
7 changed files with 48 additions and 20 deletions

View file

@ -1,6 +1,7 @@
import { cc, dlopen, FFIType } from "bun:ffi";
import source from "./matrixcc.c" with { type: "file"};
// START TINYCC
import source from "./matrixcc.c" with { type: "file"};
const {
symbols: { matrixcc },
@ -9,7 +10,7 @@ const {
symbols: {
matrixcc: {
args: [],
returns: "int",
returns: FFIType.int,
},
},
});
@ -19,30 +20,19 @@ function jsCC() {
const start = performance.now();
matrixcc();
symbols.matrixcc();
const end = performance.now();
console.log(`TinyCC Execution Time: ${end - start}ms`);
}
// END TINYCC
// Funzione JavaScript equivalente
function jsTest() {
const start = performance.now();
matrixjs();
const end = performance.now();
console.log(`JavaScript Execution Time: ${end - start}ms`);
}
// START GCC shared lib
// Carica la libreria C
const path = `./bin/matrix.so`;
const path = `./bin/matrix03.so`;
const { symbols } = dlopen(path, {
matrix: {
args: [], // La funzione C non prende argomenti
@ -61,7 +51,21 @@ function cTest() {
console.log(`C Execution Time: ${end - start}ms`);
}
// test matrix
// END GCC
// Funzione JavaScript equivalente
function jsTest() {
const start = performance.now();
matrixjs();
const end = performance.now();
console.log(`JavaScript Execution Time: ${end - start}ms`);
}
// test matrix JS
function matrixjs( n = 1500) {
let a = [];