dio cane
This commit is contained in:
parent
4992ad603e
commit
53528bc35e
7 changed files with 48 additions and 20 deletions
40
index.js
40
index.js
|
|
@ -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 = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue