diff --git a/.gitignore b/.gitignore index 2acc633..2c71022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore -bin/* - # Logs logs diff --git a/README.md b/README.md new file mode 100644 index 0000000..48dc076 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# BUN-test + +Test bun linux, windows ecc + +## Test GCC and CLANG with -o3 + +```sh +pansi21@legolas-pX:~/Scrivania/BUN-test$ gcc -Wall -O3 Cmatrix.c -o bin/Cmatrix +pansi21@legolas-pX:~/Scrivania/BUN-test$ ./bin/Cmatrix +Time measured: 12.0505566200 seconds. +``` + +```sh +pansi21@legolas-pX:~/Scrivania/BUN-test$ clang -Wall -O3 Cmatrix.c -o bin/Cmatrixclang +pansi21@legolas-pX:~/Scrivania/BUN-test$ ./bin/Cmatrixclang +Time measured: 11.8433468890 seconds. +``` + +## Tempi BUN + ( TinyCC compilazione + Esecuzione ) + exec GCC lib.so + +```sh +pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js +TinyCC Execution Time: 39841.047652ms +JavaScript Execution Time: 151445.86563ms +C Execution Time: 11306.60097ms +``` \ No newline at end of file diff --git a/bin/Cmatrix b/bin/Cmatrix new file mode 100755 index 0000000..a4e00bf Binary files /dev/null and b/bin/Cmatrix differ diff --git a/bin/Cmatrixclang b/bin/Cmatrixclang new file mode 100755 index 0000000..8e280ff Binary files /dev/null and b/bin/Cmatrixclang differ diff --git a/bin/matrix.so b/bin/matrix.so new file mode 100755 index 0000000..a968ce9 Binary files /dev/null and b/bin/matrix.so differ diff --git a/bin/matrix03.so b/bin/matrix03.so new file mode 100755 index 0000000..2818b84 Binary files /dev/null and b/bin/matrix03.so differ diff --git a/index.js b/index.js index a84fed6..c9e3d1d 100644 --- a/index.js +++ b/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 = [];