finish
This commit is contained in:
parent
53528bc35e
commit
41118a002a
7 changed files with 61 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||||
|
|
||||||
|
BuildBIN
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
|
|
||||||
|
|
|
||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"time.h": "c"
|
"time.h": "c",
|
||||||
|
"stdio.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
48
README.md
48
README.md
|
|
@ -23,4 +23,50 @@ pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
TinyCC Execution Time: 39841.047652ms
|
TinyCC Execution Time: 39841.047652ms
|
||||||
JavaScript Execution Time: 151445.86563ms
|
JavaScript Execution Time: 151445.86563ms
|
||||||
C Execution Time: 11306.60097ms
|
C Execution Time: 11306.60097ms
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## GCC senza ottimizzazioni ( -O0 )
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
|
C Execution Time: 2210.778096ms
|
||||||
|
TinyCC Execution Time: 9515.602825ms
|
||||||
|
JavaScript Execution Time: 17464.264817ms
|
||||||
|
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ gcc -Wall -O0 -shared matrix.c -o bin/matrix03.so
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
|
C Execution Time: 10084.689972ms
|
||||||
|
TinyCC Execution Time: 9475.667019999999ms
|
||||||
|
JavaScript Execution Time: 17810.901714ms
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## SetN = 2000
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ gcc -Wall -O3 -shared matrix.c -o bin/matrix03.so
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
|
C Execution Time: 48145.866321ms
|
||||||
|
TinyCC Execution Time: 102745.97170400001ms
|
||||||
|
JavaScript Execution Time: 397706.84388400003ms
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1500
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
|
C Execution Time: 10959.741538999999ms
|
||||||
|
TinyCC Execution Time: 36574.850994ms
|
||||||
|
JavaScript Execution Time: 137350.96834400002ms
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1000
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ gcc -Wall -O3 -shared matrix.c -o bin/matrix03.so
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bun run index.js
|
||||||
|
C Execution Time: 2267.1350589999997ms
|
||||||
|
TinyCC Execution Time: 10732.041204000001ms
|
||||||
|
JavaScript Execution Time: 19499.030189999998ms
|
||||||
|
```
|
||||||
|
|
|
||||||
BIN
bin/matrix03.so
BIN
bin/matrix03.so
Binary file not shown.
15
index.js
15
index.js
|
|
@ -3,13 +3,16 @@ import { cc, dlopen, FFIType } from "bun:ffi";
|
||||||
// START TINYCC
|
// START TINYCC
|
||||||
import source from "./matrixcc.c" with { type: "file"};
|
import source from "./matrixcc.c" with { type: "file"};
|
||||||
|
|
||||||
|
const setN = 1000;
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
symbols: { matrixcc },
|
symbols: { matrixcc },
|
||||||
} = cc({
|
} = cc({
|
||||||
source,
|
source,
|
||||||
symbols: {
|
symbols: {
|
||||||
matrixcc: {
|
matrixcc: {
|
||||||
args: [],
|
args: [ FFIType.int ],
|
||||||
returns: FFIType.int,
|
returns: FFIType.int,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -20,7 +23,7 @@ function jsCC() {
|
||||||
|
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
|
|
||||||
symbols.matrixcc();
|
matrixcc( setN );
|
||||||
|
|
||||||
const end = performance.now();
|
const end = performance.now();
|
||||||
console.log(`TinyCC Execution Time: ${end - start}ms`);
|
console.log(`TinyCC Execution Time: ${end - start}ms`);
|
||||||
|
|
@ -35,7 +38,7 @@ function jsCC() {
|
||||||
const path = `./bin/matrix03.so`;
|
const path = `./bin/matrix03.so`;
|
||||||
const { symbols } = dlopen(path, {
|
const { symbols } = dlopen(path, {
|
||||||
matrix: {
|
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
|
returns: FFIType.int, // La funzione C restituisce un intero
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -45,7 +48,7 @@ function cTest() {
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
|
|
||||||
// Chiama la funzione C per eseguire il test
|
// Chiama la funzione C per eseguire il test
|
||||||
symbols.matrix();
|
symbols.matrix( setN );
|
||||||
|
|
||||||
const end = performance.now();
|
const end = performance.now();
|
||||||
console.log(`C Execution Time: ${end - start}ms`);
|
console.log(`C Execution Time: ${end - start}ms`);
|
||||||
|
|
@ -66,7 +69,7 @@ function jsTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test matrix JS
|
// test matrix JS
|
||||||
function matrixjs( n = 1500) {
|
function matrixjs( n = setN) {
|
||||||
|
|
||||||
let a = [];
|
let a = [];
|
||||||
let b = [];
|
let b = [];
|
||||||
|
|
@ -108,8 +111,8 @@ function matrixjs( n = 1500) {
|
||||||
|
|
||||||
|
|
||||||
// Avvia i test
|
// Avvia i test
|
||||||
|
cTest();
|
||||||
jsCC();
|
jsCC();
|
||||||
jsTest();
|
jsTest();
|
||||||
cTest();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
2
matrix.c
2
matrix.c
|
|
@ -6,7 +6,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int matrix(int n) {
|
int matrix(int n) {
|
||||||
n = 1500;
|
n = 1000;
|
||||||
|
|
||||||
int **a = malloc(n * sizeof(int *));
|
int **a = malloc(n * sizeof(int *));
|
||||||
int **b = malloc(n * sizeof(int *));
|
int **b = malloc(n * sizeof(int *));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int matrixcc(int n) {
|
int matrixcc(int n) {
|
||||||
n = 1500;
|
//n = 1500;
|
||||||
|
|
||||||
int **a = malloc(n * sizeof(int *));
|
int **a = malloc(n * sizeof(int *));
|
||||||
int **b = malloc(n * sizeof(int *));
|
int **b = malloc(n * sizeof(int *));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue