Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
from datetime import timedelta
|
| 4 |
+
import numpy as np
|
| 5 |
+
from threading import Thread
|
| 6 |
+
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
+
def cpu_benchmark(cores, iterations=1000000):
|
| 10 |
+
start = time.perf_counter()
|
| 11 |
+
|
| 12 |
+
num_threads = min([int(core * iterations / cores) for core in range(cores)] + [1])
|
| 13 |
+
threads = []
|
| 14 |
+
|
| 15 |
+
results = []
|
| 16 |
+
for i in range(cores):
|
| 17 |
+
t = Thread(target=np.random.randn, args=(num_threads[i],))
|
| 18 |
+
threads.append(t)
|
| 19 |
+
t.start()
|
| 20 |
+
|
| 21 |
+
for t in threads:
|
| 22 |
+
t.join()
|
| 23 |
+
|
| 24 |
+
end = time.perf_counter()
|
| 25 |
+
elapsed = end - start
|
| 26 |
+
return elapsed / iterations, elapsed
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
st.title("CPU Benchmark")
|
| 30 |
+
st.write("Select the number of cores to use for the benchmark.")
|
| 31 |
+
|
| 32 |
+
cores = int(st.slider("Number of Cores", 1, os.cpu_count(), step=1))
|
| 33 |
+
submit_button = st.button("Run Benchmark")
|
| 34 |
+
|
| 35 |
+
if submit_button:
|
| 36 |
+
elapsed_time, total_time = cpu_benchmark(cores)
|
| 37 |
+
result = f"Elapsed Time per Iteration: {elapsed_time:.6f} seconds\nTotal Time: {total_time:.6f} seconds"
|
| 38 |
+
st.success(result)
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
main()
|