Spaces:
Running on Zero
Running on Zero
Download utils/profile_frombuffer.py from yslan/GaussianAnything-AIGC3D: direct link, hf CLI and curl.
- Browser
- Download file 719 Bytes
-
https://huggingface.co/spaces/yslan/GaussianAnything-AIGC3D/resolve/main/utils/profile_frombuffer.py
- Command line
-
hf download hf://spaces/yslan/GaussianAnything-AIGC3D/utils/profile_frombuffer.py
-
curl -L -o profile_frombuffer.py https://huggingface.co/spaces/yslan/GaussianAnything-AIGC3D/resolve/main/utils/profile_frombuffer.py
719 Bytes
| import numpy as np | |
| from numba import jit | |
| import time | |
| # Numba-optimized function without reshape | |
| def from_buffer_fast(buf): | |
| return np.frombuffer(buf, dtype=np.uint8) | |
| # Benchmarking function | |
| def benchmark(func, buf): | |
| start_time = time.time() | |
| func(buf) | |
| end_time = time.time() | |
| return end_time - start_time | |
| # Generate random buffer and dtype | |
| buf = np.random.randint(0, 255, size=10**6, dtype=np.uint8).tobytes() | |
| # Benchmark np.frombuffer | |
| original_time = benchmark(np.frombuffer, buf) | |
| print("np.frombuffer time:", original_time) | |
| # Benchmark Numba-optimized function without reshape | |
| numba_time = benchmark(from_buffer_fast, buf) | |
| print("Numba-optimized function time:", numba_time) | |