This commit is contained in:
PanSi21 2025-01-05 19:11:48 +01:00
parent 53528bc35e
commit 41118a002a
Signed by untrusted user who does not match committer: PanSi21
GPG key ID: 755F8874C65EF462
7 changed files with 61 additions and 10 deletions

View file

@ -3,13 +3,16 @@ import { cc, dlopen, FFIType } from "bun:ffi";
// START TINYCC
import source from "./matrixcc.c" with { type: "file"};
const setN = 1000;
const {
symbols: { matrixcc },
} = cc({
source,
symbols: {
matrixcc: {
args: [],
args: [ FFIType.int ],
returns: FFIType.int,
},
},
@ -20,7 +23,7 @@ function jsCC() {
const start = performance.now();
symbols.matrixcc();
matrixcc( setN );
const end = performance.now();
console.log(`TinyCC Execution Time: ${end - start}ms`);
@ -35,7 +38,7 @@ function jsCC() {
const path = `./bin/matrix03.so`;
const { symbols } = dlopen(path, {
matrix: {
args: [], // La funzione C non prende argomenti
args: [ FFIType.int ], // La funzione C non prende argomenti
returns: FFIType.int, // La funzione C restituisce un intero
},
});
@ -45,7 +48,7 @@ function cTest() {
const start = performance.now();
// Chiama la funzione C per eseguire il test
symbols.matrix();
symbols.matrix( setN );
const end = performance.now();
console.log(`C Execution Time: ${end - start}ms`);
@ -66,7 +69,7 @@ function jsTest() {
}
// test matrix JS
function matrixjs( n = 1500) {
function matrixjs( n = setN) {
let a = [];
let b = [];
@ -108,8 +111,8 @@ function matrixjs( n = 1500) {
// Avvia i test
cTest();
jsCC();
jsTest();
cTest();