Finish Tests
This commit is contained in:
parent
3315118690
commit
4992ad603e
13 changed files with 398 additions and 53 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,8 +1,10 @@
|
|||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
|
||||
bin/*
|
||||
|
||||
# Logs
|
||||
|
||||
meow
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
|
|
|
|||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"time.h": "c"
|
||||
}
|
||||
}
|
||||
67
Cmatrix.c
Normal file
67
Cmatrix.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// For GCC and Clang
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
void parseH(char *p);
|
||||
void parseL(char *p);
|
||||
|
||||
void matrix_multiplication(int n) {
|
||||
int **a = malloc(n * sizeof(int *));
|
||||
int **b = malloc(n * sizeof(int *));
|
||||
int **c = malloc(n * sizeof(int *));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = malloc(n * sizeof(int));
|
||||
b[i] = malloc(n * sizeof(int));
|
||||
c[i] = malloc(n * sizeof(int));
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = rand() % 100;
|
||||
b[i][j] = rand() % 100;
|
||||
c[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int k = 0; k < n; k++) {
|
||||
c[i][j] += a[i][k] * b[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
free(a[i]);
|
||||
free(b[i]);
|
||||
free(c[i]);
|
||||
}
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Start measuring time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
// END
|
||||
|
||||
matrix_multiplication(1500);
|
||||
|
||||
|
||||
// Stop measuring time and calculate the elapsed time
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
long seconds = end.tv_sec - begin.tv_sec;
|
||||
long nanoseconds = end.tv_nsec - begin.tv_nsec;
|
||||
double elapsed = seconds + nanoseconds * 1e-9;
|
||||
|
||||
printf("Time measured: %.10f seconds.\n", elapsed);
|
||||
//
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# BUN-test
|
||||
|
||||
Test bun linux, windows ecc
|
||||
87
bebbo.c
Normal file
87
bebbo.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
void parseH(char *p);
|
||||
void parseL(char *p);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
// Start measuring time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
char c[] = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
||||
|
||||
parseH(c);
|
||||
parseL(c);
|
||||
//printf("%s\n", c);
|
||||
|
||||
// Stop measuring time and calculate the elapsed time
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
long seconds = end.tv_sec - begin.tv_sec;
|
||||
long nanoseconds = end.tv_nsec - begin.tv_nsec;
|
||||
double elapsed = seconds + nanoseconds * 1e-9;
|
||||
|
||||
printf("Time measured: %.10f seconds.\n", elapsed);
|
||||
//
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void parseH(char *p)
|
||||
{
|
||||
|
||||
int ln = strlen(p);
|
||||
|
||||
for (int a = 0; a < ln; a++)
|
||||
{
|
||||
if (p[a] < 123 && p[a] > 96)
|
||||
{
|
||||
p[a] = p[a] - 32;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
char *t ;
|
||||
t=p;
|
||||
while(*t!=0){
|
||||
if(*t>96 && *t<123){
|
||||
*t=*t-32;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void parseL(char *p)
|
||||
{
|
||||
|
||||
/*
|
||||
char *t ;
|
||||
t=p;
|
||||
while(*t!=0){
|
||||
if(*t>64 && *t<91){
|
||||
*t=*t+32;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
*/
|
||||
|
||||
int ln = strlen(p);
|
||||
for (int a = 0; a < ln; a++)
|
||||
{
|
||||
if (p[a] < 91 && p[a] > 64)
|
||||
{
|
||||
p[a] = p[a] + 32;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
bebbow.c
Normal file
67
bebbow.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
void parseH(char *p);
|
||||
void parseL(char *p);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
// Start measuring time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
char c[] = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
||||
|
||||
parseH(c);
|
||||
parseL(c);
|
||||
//printf("%s\n", c);
|
||||
|
||||
// Stop measuring time and calculate the elapsed time
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
long seconds = end.tv_sec - begin.tv_sec;
|
||||
long nanoseconds = end.tv_nsec - begin.tv_nsec;
|
||||
double elapsed = seconds + nanoseconds * 1e-9;
|
||||
|
||||
printf("Time measured: %.10f seconds.\n", elapsed);
|
||||
//
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void parseH(char *p)
|
||||
{
|
||||
|
||||
|
||||
|
||||
char *t ;
|
||||
t=p;
|
||||
while(*t!=0){
|
||||
if(*t>96 && *t<123){
|
||||
*t=*t-32;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void parseL(char *p)
|
||||
{
|
||||
|
||||
char *t ;
|
||||
t=p;
|
||||
while(*t!=0){
|
||||
if(*t>64 && *t<91){
|
||||
*t=*t+32;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
|
||||
}
|
||||
93
index.js
93
index.js
|
|
@ -1,19 +1,40 @@
|
|||
import { dlopen, FFIType } from "bun:ffi";
|
||||
import { cc, dlopen, FFIType } from "bun:ffi";
|
||||
import source from "./matrixcc.c" with { type: "file"};
|
||||
|
||||
|
||||
const {
|
||||
symbols: { matrixcc },
|
||||
} = cc({
|
||||
source,
|
||||
symbols: {
|
||||
matrixcc: {
|
||||
args: [],
|
||||
returns: "int",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Funzione JavaScript equivalente
|
||||
function jsCC() {
|
||||
|
||||
function jsTest() {
|
||||
let c = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
||||
let j = '';
|
||||
let h = '';
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
for (let a = 0; a < 100000 ; a++) {
|
||||
h = c.toUpperCase();
|
||||
j = h.toLowerCase();
|
||||
c = j;
|
||||
}
|
||||
matrixcc();
|
||||
|
||||
const end = performance.now();
|
||||
console.log(`TinyCC Execution Time: ${end - start}ms`);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Funzione JavaScript equivalente
|
||||
function jsTest() {
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
matrixjs();
|
||||
|
||||
const end = performance.now();
|
||||
console.log(`JavaScript Execution Time: ${end - start}ms`);
|
||||
|
|
@ -21,9 +42,9 @@ function jsTest() {
|
|||
|
||||
|
||||
// Carica la libreria C
|
||||
const path = `./libtesticolo.so`;
|
||||
const path = `./bin/matrix.so`;
|
||||
const { symbols } = dlopen(path, {
|
||||
testicolo: {
|
||||
matrix: {
|
||||
args: [], // La funzione C non prende argomenti
|
||||
returns: FFIType.int, // La funzione C restituisce un intero
|
||||
},
|
||||
|
|
@ -34,13 +55,57 @@ function cTest() {
|
|||
const start = performance.now();
|
||||
|
||||
// Chiama la funzione C per eseguire il test
|
||||
symbols.testicolo();
|
||||
symbols.matrix();
|
||||
|
||||
const end = performance.now();
|
||||
console.log(`C Execution Time: ${end - start}ms`);
|
||||
}
|
||||
|
||||
// test matrix
|
||||
function matrixjs( n = 1500) {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Avvia i test
|
||||
jsCC();
|
||||
jsTest();
|
||||
cTest();
|
||||
|
||||
|
||||
|
|
|
|||
BIN
libfibonacci.so
BIN
libfibonacci.so
Binary file not shown.
BIN
libtesticolo.so
BIN
libtesticolo.so
Binary file not shown.
45
matrix.c
Normal file
45
matrix.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// for shared lib
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int matrix(int n) {
|
||||
n = 1500;
|
||||
|
||||
int **a = malloc(n * sizeof(int *));
|
||||
int **b = malloc(n * sizeof(int *));
|
||||
int **c = malloc(n * sizeof(int *));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = malloc(n * sizeof(int));
|
||||
b[i] = malloc(n * sizeof(int));
|
||||
c[i] = malloc(n * sizeof(int));
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = rand() % 100;
|
||||
b[i][j] = rand() % 100;
|
||||
c[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int k = 0; k < n; k++) {
|
||||
c[i][j] += a[i][k] * b[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
free(a[i]);
|
||||
free(b[i]);
|
||||
free(c[i]);
|
||||
}
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
45
matrixcc.c
Normal file
45
matrixcc.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// for TinyCC
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int matrixcc(int n) {
|
||||
n = 1500;
|
||||
|
||||
int **a = malloc(n * sizeof(int *));
|
||||
int **b = malloc(n * sizeof(int *));
|
||||
int **c = malloc(n * sizeof(int *));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = malloc(n * sizeof(int));
|
||||
b[i] = malloc(n * sizeof(int));
|
||||
c[i] = malloc(n * sizeof(int));
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = rand() % 100;
|
||||
b[i][j] = rand() % 100;
|
||||
c[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int k = 0; k < n; k++) {
|
||||
c[i][j] += a[i][k] * b[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
free(a[i]);
|
||||
free(b[i]);
|
||||
free(c[i]);
|
||||
}
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
BIN
meow
BIN
meow
Binary file not shown.
35
test.c
35
test.c
|
|
@ -1,35 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int testicolo( void ) {
|
||||
|
||||
char c[] = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
|
||||
|
||||
for(int a=0;a<100000;a++){
|
||||
parseH(&c);
|
||||
parseL(&c);
|
||||
// printf("%s",c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void parseH(char *p){
|
||||
int ln=strlen(p);
|
||||
for(int a=0; a<ln; a++){
|
||||
if(p[a]<123 && p[a]>96){
|
||||
p[a]=p[a]-32;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void parseL(char *p){
|
||||
int ln=strlen(p);
|
||||
for(int a=0; a<ln; a++){
|
||||
if(p[a]<91 && p[a]>64){
|
||||
p[a]=p[a]+32;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue