MCPcopy Create free account
hub / github.com/FastLED/FastLED / demo_performance

Function demo_performance

ci/examples/fingerprint_cache_demo.py:147–198  ·  view source on GitHub ↗

Demonstrate cache performance characteristics.

()

Source from the content-addressed store, hash-verified

145
146
147def demo_performance() -> None:
148 """Demonstrate cache performance characteristics."""
149 print("\n=== Performance Demo ===")
150
151 with tempfile.TemporaryDirectory() as temp_dir:
152 temp_path = Path(temp_dir)
153 cache_file = temp_path / "perf_cache.json"
154 cache = FingerprintCache(cache_file)
155
156 # Create multiple test files
157 num_files = 20
158 test_files: list[Path] = []
159
160 for i in range(num_files):
161 test_file = temp_path / f"file_{i:03d}.cpp"
162 with open(test_file, "w") as f:
163 f.write(
164 f"// File {i}\n#include <iostream>\nint func_{i}() {{ return {i}; }}"
165 )
166 test_files.append(test_file)
167
168 print(f"Created {num_files} test files")
169
170 # Measure cache miss performance (first check)
171 start_time = time.time()
172 baseline_time = time.time() - 3600
173
174 for test_file in test_files:
175 cache.has_changed(test_file, baseline_time)
176
177 miss_time = time.time() - start_time
178 print(
179 f"Cache miss time: {miss_time * 1000:.1f}ms ({miss_time * 1000 / num_files:.2f}ms per file)"
180 )
181
182 # Measure cache hit performance (second check with same modtime)
183 modtimes = [os.path.getmtime(f) for f in test_files]
184
185 start_time = time.time()
186 for test_file, modtime in zip(test_files, modtimes):
187 cache.has_changed(test_file, modtime)
188
189 hit_time = time.time() - start_time
190 print(
191 f"Cache hit time: {hit_time * 1000:.1f}ms ({hit_time * 1000 / num_files:.2f}ms per file)"
192 )
193 print(f"Speedup: {miss_time / hit_time:.1f}x faster")
194
195 # Show cache statistics
196 stats = cache.get_cache_stats()
197 print(f"Cache entries: {stats['total_entries']}")
198 print(f"Cache file size: {stats['cache_file_size_bytes']} bytes")
199
200
201def demo_convenience_function() -> None:

Callers 1

Calls 7

has_changedMethod · 0.95
get_cache_statsMethod · 0.95
FingerprintCacheClass · 0.90
timeMethod · 0.80
printFunction · 0.50
writeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected