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

2
.gitignore vendored
View file

@ -1,8 +1,6 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
bin/*
# Logs # Logs
logs logs

26
README.md Normal file
View file

@ -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
```

BIN
bin/Cmatrix Executable file

Binary file not shown.

BIN
bin/Cmatrixclang Executable file

Binary file not shown.

BIN
bin/matrix.so Executable file

Binary file not shown.

BIN
bin/matrix03.so Executable file

Binary file not shown.

View file

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