Add Matrix-based Benchmark

This commit is contained in:
Alauddin Maulana Hirzan 2024-06-16 15:06:22 +07:00
parent 0349c9e4a7
commit c8212ebfda
Signed by: maulanahirzan
GPG key ID: 484DAC952787FA13
3 changed files with 66 additions and 3 deletions

View file

@ -0,0 +1,9 @@
from LunaDB import LunaDB
db = LunaDB('db.json')
collection = db.table("Blockchain", id_field="id")
collection.insert({"id": 1,"city": "Semarang"})
collection.insert({"id": 2,"city": "Jakarta"})
print(db)

View file

@ -0,0 +1,53 @@
import numpy as np
from tqdm import tqdm
from time import time
class MatrixBench():
def __init__(self, iters: int, size: int):
self.iters = iters
self.size = size
self.average = 0
self.start_time = 0
self.end_time = 0
self.elapsed_time = 0
self.flops:float = 0.0
def create_matrices(self):
# Create num x num matrix and an num x 1 vector with random floating point numbers
self.matrix_A = np.random.rand(self.size, self.size).astype(np.float32)
self.matrix_B = np.random.rand(self.size).astype(np.float32)
def do_operation(self):
# Do Floating Point Operation
self.start_time = time()
_ = np.linalg.solve(self.matrix_A, self.matrix_B)
self.end_time = time()
def do_calculate(self):
# Calculate Floating Point Operation per Second (FLOPS)
self.elapsed_time = self.end_time - self.start_time
self.num_operations = (2 / 3) * self.size **3
self.flops = self.num_operations / self.elapsed_time
self.average += self.flops
def run(self):
print("# Linpack-like Matrix-based Floating Point Benchmark #")
for i in tqdm(range(self.iters), desc="Running Matrix-based Benchmark..."):
self.create_matrices()
self.do_operation()
self.do_calculate()
self.avg_flops: float = (self.average/self.iters) / 1000000
print(f"Result : {self.avg_flops:.2f} MFLOPS")
def main():
# Adjust Matrix Size
size = 192
# Adjust Iteration Time
iters = 10000
# Run Benchmark
bench = MatrixBench(iters=iters, size=size)
bench.run()
main()

View file

@ -3,7 +3,8 @@
This repository contains useful programs written in **Python 3.9**. Each folder accompanied with **requirements.txt** for easier dependency access.
## Currently Available: ##
* Benchmark Program : using **psutil** to obtain performance
* Pickle Compress Program : compress variable dumps using **gzip**, **bzip2**, **lzma**, or **no compression at all**
* FastAPI Simple Example (Normal Request, GET Request, HTML Request)
* **Benchmark Program** : using **psutil** to obtain computer performance
* **Pickle Compress Program** : compress variable dumps using **gzip**, **bzip2**, **lzma**, or **no compression at all**
* **FastAPI Simple Example** : contains API standard operations (Normal Request, GET Request, HTML Request)
* **Matrix-based Bencmark** : contains a class to recreate Linpack (Matrix-based) Floating-point Per Second (FLOPS) Benchmark. Based on **numpy** lib
* *adding more soon*