Update MIPS Benchmark

This commit is contained in:
Alauddin Maulana Hirzan 2024-06-17 13:51:09 +07:00
parent 575c687363
commit 6534605b6b
Signed by: maulanahirzan
GPG key ID: 484DAC952787FA13
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,49 @@
import numpy as np
from time import time
class MIPSBenchmark:
def __init__(self, iters: int):
self.iters = iters
self.start_time = 0
self.end_time = 0
self.elapsed_time = 0
self.total_instructions = 0
self.mips = 0
def ips_operation(self):
# Run basic 7 ALU operations
_ = np.random.randint(10) + np.random.randint(10)
_ = np.random.randint(10) - np.random.randint(10)
_ = np.random.randint(10) * np.random.randint(10)
_ = np.random.randint(10) // (np.random.randint(10) + 1) # Prevent Division by Zero
_ = np.random.choice([True, False]) & np.random.choice([True, False])
_ = np.random.choice([True, False]) | np.random.choice([True, False])
_ = np.random.choice([True, False]) ^ np.random.choice([True, False])
def calculate(self):
self.elapsed_time = self.end_time - self.start_time
self.total_instructions = self.iters*7
self.mips = (self.total_instructions / self.elapsed_time) / 1000000
print(f"=> Executed {self.total_instructions} within {self.elapsed_time}\n=> Result : {self.mips:.2f} MIPS")
def run(self):
print("# MIPS CPU Benchmark #")
print("# Running 7 Basic ALU Ops #")
self.start_time = time()
for i in range(1, self.iters+1):
print(f"=> Running Iteration #{str(i)}", end="\r")
self.ips_operation()
print("\n")
self.end_time = time()
self.calculate()
def main():
iters = 1000000 # Minimum 1,000,000 times
bench = MIPSBenchmark(iters=iters)
bench.run()
main()

View file

@ -7,4 +7,5 @@ This repository contains useful programs written in **Python 3.9**. Each folder
* **Pickle Compress Program** : compress variable dumps using **gzip**, **bzip2**, **lzma**, or **no compression at all** * **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) * **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** or **scipy** libs * **Matrix-based Bencmark** : contains a class to recreate Linpack (Matrix-based) Floating-point Per Second (FLOPS) Benchmark. Based on **numpy** or **scipy** libs
* **MIPS-Benchmark** : contains a script to benchmark your CPU's Intrusion Execution Speed (Million Instructions Per Second). The result might be lower but consistent on numerous runs.
* *adding more soon* * *adding more soon*