From 41118a002a7b9dde30bc3121b75a14688b91af91 Mon Sep 17 00:00:00 2001 From: PanSi21 Date: Sun, 5 Jan 2025 19:11:48 +0100 Subject: [PATCH] finish --- .gitignore | 1 + .vscode/settings.json | 3 ++- README.md | 48 +++++++++++++++++++++++++++++++++++++++++- bin/matrix03.so | Bin 15576 -> 15576 bytes index.js | 15 +++++++------ matrix.c | 2 +- matrixcc.c | 2 +- 7 files changed, 61 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2c71022..b234ca5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore +BuildBIN # Logs diff --git a/.vscode/settings.json b/.vscode/settings.json index bf32034..e7d9621 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - "time.h": "c" + "time.h": "c", + "stdio.h": "c" } } \ No newline at end of file diff --git a/README.md b/README.md index 48dc076..b0603b7 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,50 @@ 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 +``` + + +## 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 +``` diff --git a/bin/matrix03.so b/bin/matrix03.so index 2818b8474273dab243da27a68410dea941b87b0e..41333712bfc692a69e3cad59d144690e0b8e6a10 100755 GIT binary patch delta 195 zcmcand82Z}4JHw1ef<+>O@+hf+Fn1Rsv&!SI)4%K<~K~$d@&C43=FP@{~f~|Lmfjx zgFTwxNW5VD|NsAfkc3Aki^_}7|KPmCFP;H89-S^K9QzmWGcXvweQ^~e3u1eA9`opC zQSs|Ev3PL+A~^Z5U@<>Pu5^iK^KlN(#{UlTlU;@E6kad`#hyEM@)&wFA7k-o{0CNa Z&a?RtP|+`-qQyc+Ob+s!uM0710RZ!^Q(*uA delta 195 zcmcand82Z}4JHx4_$5jPUu{(8yh_>jC^|740Q|% z4fbe$Bk_Xq|NsB{K@uLFEGjQP|AX@mzjy}Zcyzj`aO^J-XJ9aV`{F7{7R2`KJm%5O zqT<(SV)5btL~!z9!D4=pTx ZInU-pKt;cRiWUnQF+I@Rd|il93ji$$SXBT3 diff --git a/index.js b/index.js index c9e3d1d..fb1fe04 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,16 @@ import { cc, dlopen, FFIType } from "bun:ffi"; // START TINYCC import source from "./matrixcc.c" with { type: "file"}; +const setN = 1000; + + const { symbols: { matrixcc }, } = cc({ source, symbols: { matrixcc: { - args: [], + args: [ FFIType.int ], returns: FFIType.int, }, }, @@ -20,7 +23,7 @@ function jsCC() { const start = performance.now(); - symbols.matrixcc(); + matrixcc( setN ); const end = performance.now(); console.log(`TinyCC Execution Time: ${end - start}ms`); @@ -35,7 +38,7 @@ function jsCC() { const path = `./bin/matrix03.so`; const { symbols } = dlopen(path, { 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 }, }); @@ -45,7 +48,7 @@ function cTest() { const start = performance.now(); // Chiama la funzione C per eseguire il test - symbols.matrix(); + symbols.matrix( setN ); const end = performance.now(); console.log(`C Execution Time: ${end - start}ms`); @@ -66,7 +69,7 @@ function jsTest() { } // test matrix JS -function matrixjs( n = 1500) { +function matrixjs( n = setN) { let a = []; let b = []; @@ -108,8 +111,8 @@ function matrixjs( n = 1500) { // Avvia i test +cTest(); jsCC(); jsTest(); -cTest(); diff --git a/matrix.c b/matrix.c index 87244d2..037b23c 100644 --- a/matrix.c +++ b/matrix.c @@ -6,7 +6,7 @@ #include int matrix(int n) { - n = 1500; + n = 1000; int **a = malloc(n * sizeof(int *)); int **b = malloc(n * sizeof(int *)); diff --git a/matrixcc.c b/matrixcc.c index c7d748a..e599f5c 100644 --- a/matrixcc.c +++ b/matrixcc.c @@ -6,7 +6,7 @@ #include int matrixcc(int n) { - n = 1500; + //n = 1500; int **a = malloc(n * sizeof(int *)); int **b = malloc(n * sizeof(int *));