dio cane
This commit is contained in:
parent
4992ad603e
commit
53528bc35e
7 changed files with 48 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,8 +1,6 @@
|
|||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
|
||||
bin/*
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
|
|
|
|||
26
README.md
Normal file
26
README.md
Normal 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
BIN
bin/Cmatrix
Executable file
Binary file not shown.
BIN
bin/Cmatrixclang
Executable file
BIN
bin/Cmatrixclang
Executable file
Binary file not shown.
BIN
bin/matrix.so
Executable file
BIN
bin/matrix.so
Executable file
Binary file not shown.
BIN
bin/matrix03.so
Executable file
BIN
bin/matrix03.so
Executable file
Binary file not shown.
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