test.sh
This commit is contained in:
parent
0191d024e4
commit
a81950853e
4 changed files with 144 additions and 1 deletions
28
README.md
28
README.md
|
|
@ -70,3 +70,31 @@ C Execution Time: 2267.1350589999997ms
|
||||||
TinyCC Execution Time: 10732.041204000001ms
|
TinyCC Execution Time: 10732.041204000001ms
|
||||||
JavaScript Execution Time: 19499.030189999998ms
|
JavaScript Execution Time: 19499.030189999998ms
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## test.sh con n = 300
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bash test.sh
|
||||||
|
Bun Execution Results:
|
||||||
|
Mean Time (ms): 241.13
|
||||||
|
Standard Deviation: 21.91
|
||||||
|
|
||||||
|
Node Execution Results:
|
||||||
|
Mean Time (ms): 274.54
|
||||||
|
Standard Deviation: 12.86
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## test.sh con n = 500
|
||||||
|
```sh
|
||||||
|
pansi21@legolas-pX:~/Scrivania/BUN-test$ bash test.sh
|
||||||
|
Bun Execution Results:
|
||||||
|
Mean Time (ms): 1030.54
|
||||||
|
Standard Deviation: 36.02
|
||||||
|
|
||||||
|
Node Execution Results:
|
||||||
|
Mean Time (ms): 797.34
|
||||||
|
Standard Deviation: 30.81
|
||||||
|
```
|
||||||
5
index.js
5
index.js
|
|
@ -1,9 +1,12 @@
|
||||||
|
|
||||||
|
const setN = 1000;
|
||||||
|
|
||||||
import { cc, dlopen, FFIType } from "bun:ffi";
|
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 {
|
||||||
|
|
|
||||||
54
only.js
Normal file
54
only.js
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
const setN = 500; // Imposta la dimensione della matrice
|
||||||
|
// test matrix JS
|
||||||
|
function matrixjs( n = setN) {
|
||||||
|
|
||||||
|
let a = [];
|
||||||
|
let b = [];
|
||||||
|
let c = [];
|
||||||
|
|
||||||
|
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
a[i] = [];
|
||||||
|
b[i] = [];
|
||||||
|
c[i] = [];
|
||||||
|
|
||||||
|
for (let j = 0; j < n; j++) {
|
||||||
|
a[i][j] = Math.floor(Math.random() * 100);
|
||||||
|
b[i][j] = Math.floor(Math.random() * 100);
|
||||||
|
c[i][j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
for (let j = 0; j < n; j++) {
|
||||||
|
for (let k = 0; k < n; k++) {
|
||||||
|
c[i][j] += a[i][k] * b[k][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
a[i].length = 0;
|
||||||
|
b[i].length = 0;
|
||||||
|
c[i].length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.length = 0;
|
||||||
|
b.length = 0;
|
||||||
|
c.length = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
// Funzione per misurare il tempo di esecuzione
|
||||||
|
function jsTest() {
|
||||||
|
const start = performance.now();
|
||||||
|
|
||||||
|
// Esegui la funzione matrixjs
|
||||||
|
matrixjs(setN);
|
||||||
|
|
||||||
|
const end = performance.now();
|
||||||
|
console.log(`JavaScript Execution Time: ${end - start}ms`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avvia il benchmark
|
||||||
|
jsTest();
|
||||||
58
test.sh
Normal file
58
test.sh
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Funzione per calcolare la media
|
||||||
|
calculate_mean() {
|
||||||
|
local sum=0
|
||||||
|
for time in "$@"; do
|
||||||
|
sum=$(echo "$sum + $time" | bc)
|
||||||
|
done
|
||||||
|
echo "scale=2; $sum / $#" | bc
|
||||||
|
}
|
||||||
|
|
||||||
|
# Funzione per calcolare la deviazione standard
|
||||||
|
calculate_std_dev() {
|
||||||
|
local mean=$1
|
||||||
|
shift
|
||||||
|
local sum=0
|
||||||
|
for time in "$@"; do
|
||||||
|
sum=$(echo "$sum + ($time - $mean)^2" | bc)
|
||||||
|
done
|
||||||
|
echo "scale=2; sqrt($sum / $#)" | bc
|
||||||
|
}
|
||||||
|
|
||||||
|
# Esegui 100 test con Bun
|
||||||
|
bun_times=()
|
||||||
|
for i in {1..100}; do
|
||||||
|
start_time=$(date +%s%3N) # Ottieni il tempo in millisecondi
|
||||||
|
bun run only.js > /dev/null
|
||||||
|
end_time=$(date +%s%3N)
|
||||||
|
elapsed_time=$((end_time - start_time))
|
||||||
|
bun_times+=($elapsed_time)
|
||||||
|
done
|
||||||
|
|
||||||
|
# Calcola la media e deviazione standard per Bun
|
||||||
|
bun_mean=$(calculate_mean "${bun_times[@]}")
|
||||||
|
bun_std_dev=$(calculate_std_dev "$bun_mean" "${bun_times[@]}")
|
||||||
|
|
||||||
|
# Esegui 100 test con Node
|
||||||
|
node_times=()
|
||||||
|
for i in {1..100}; do
|
||||||
|
start_time=$(date +%s%3N)
|
||||||
|
node only.js > /dev/null
|
||||||
|
end_time=$(date +%s%3N)
|
||||||
|
elapsed_time=$((end_time - start_time))
|
||||||
|
node_times+=($elapsed_time)
|
||||||
|
done
|
||||||
|
|
||||||
|
# Calcola la media e deviazione standard per Node
|
||||||
|
node_mean=$(calculate_mean "${node_times[@]}")
|
||||||
|
node_std_dev=$(calculate_std_dev "$node_mean" "${node_times[@]}")
|
||||||
|
|
||||||
|
# Stampa i risultati
|
||||||
|
echo "Bun Execution Results:"
|
||||||
|
echo "Mean Time (ms): $bun_mean"
|
||||||
|
echo "Standard Deviation: $bun_std_dev"
|
||||||
|
echo ""
|
||||||
|
echo "Node Execution Results:"
|
||||||
|
echo "Mean Time (ms): $node_mean"
|
||||||
|
echo "Standard Deviation: $node_std_dev"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue