@@ -16,7 +16,7 @@ def generate_test_paths(count = 1000)
1616
1717 # Mix of different path types
1818 extensions = %w[ .rb .txt .log .tmp .swp .md .yml .json .xml .css .js .html ]
19- directories = [ ' src' , ' lib' , ' test' , ' spec' , ' config' , ' docs' , ' bin' , ' tmp' , ' coverage' , ' vendor' ]
19+ directories = %w[ src lib test spec config docs bin tmp coverage vendor ]
2020
2121 count . times do |i |
2222 depth = rand ( 1 ..4 )
@@ -30,7 +30,24 @@ def generate_test_paths(count = 1000)
3030
3131# Generate gitignore patterns of varying complexity
3232def generate_patterns ( count )
33- base_patterns = [
33+ base_patterns = base_gitignore_patterns
34+
35+ # Return the first 'count' patterns, cycling if needed
36+ if count <= base_patterns . length
37+ base_patterns . take ( count )
38+ else
39+ patterns = base_patterns . dup
40+ remaining = count - base_patterns . length
41+ remaining . times do |i |
42+ patterns << "generated_pattern_#{ i } /**/*"
43+ end
44+ patterns
45+ end
46+ end
47+
48+ # rubocop:disable Metrics/MethodLength
49+ def base_gitignore_patterns
50+ [
3451 '*.log' ,
3552 '*.tmp' ,
3653 '*.swp' ,
@@ -165,31 +182,20 @@ def generate_patterns(count)
165182 '.yarn/install-state.gz' ,
166183 '.pnp.*'
167184 ]
168-
169- # Return the first 'count' patterns, cycling if needed
170- if count <= base_patterns . length
171- base_patterns . take ( count )
172- else
173- patterns = base_patterns . dup
174- remaining = count - base_patterns . length
175- remaining . times do |i |
176- patterns << "generated_pattern_#{ i } /**/*"
177- end
178- patterns
179- end
180185end
186+ # rubocop:enable Metrics/MethodLength
181187
182- puts " PathSpec Performance Benchmark"
183- puts "=" * 80
184- puts " Testing pattern matching performance with varying pattern counts"
185- puts " Hardware: Apple M4 Pro (12 cores: 8 performance + 4 efficiency), 24 GB RAM"
188+ puts ' PathSpec Performance Benchmark'
189+ puts '=' * 80
190+ puts ' Testing pattern matching performance with varying pattern counts'
191+ puts ' Hardware: Apple M4 Pro (12 cores: 8 performance + 4 efficiency), 24 GB RAM'
186192puts "Ruby Version: #{ RUBY_VERSION } "
187- puts " Test Configuration:"
193+ puts ' Test Configuration:'
188194puts " - Pattern counts: #{ PATTERN_COUNTS . join ( ', ' ) } "
189- puts " - Test paths: 1000 representative file paths"
195+ puts ' - Test paths: 1000 representative file paths'
190196puts " - Warmup time: #{ WARMUP_TIME } s"
191197puts " - Benchmark time: #{ BENCHMARK_TIME } s per test"
192- puts "=" * 80
198+ puts '=' * 80
193199puts
194200
195201# Pre-generate test data
@@ -203,15 +209,15 @@ def generate_patterns(count)
203209 pathspec = PathSpec . new ( patterns , :git )
204210
205211 puts "Benchmarking with #{ pattern_count } patterns..."
206- puts "-" * 80
212+ puts '-' * 80
207213
208214 results [ pattern_count ] = { }
209215
210216 # Benchmark 1: Single path matching
211217 Benchmark . ips do |x |
212218 x . config ( time : BENCHMARK_TIME , warmup : WARMUP_TIME )
213219
214- x . report ( " match (single path)" ) do
220+ x . report ( ' match (single path)' ) do
215221 test_paths . first ( 10 ) . each do |path |
216222 pathspec . match ( path )
217223 end
@@ -226,7 +232,7 @@ def generate_patterns(count)
226232 Benchmark . ips do |x |
227233 x . config ( time : BENCHMARK_TIME , warmup : WARMUP_TIME )
228234
229- x . report ( " match_paths (100 paths)" ) do
235+ x . report ( ' match_paths (100 paths)' ) do
230236 pathspec . match_paths ( test_paths . first ( 100 ) , '' )
231237 end
232238 end
@@ -237,19 +243,19 @@ def generate_patterns(count)
237243 Benchmark . ips do |x |
238244 x . config ( time : BENCHMARK_TIME , warmup : WARMUP_TIME )
239245
240- x . report ( " initialization" ) do
246+ x . report ( ' initialization' ) do
241247 PathSpec . new ( patterns , :git )
242248 end
243249 end
244250
245251 puts "\n "
246252end
247253
248- puts "=" * 80
249- puts " Benchmark complete!"
250- puts "=" * 80
254+ puts '=' * 80
255+ puts ' Benchmark complete!'
256+ puts '=' * 80
251257puts "\n To analyze results:"
252- puts " 1. Review the iterations/second (i/s) for each pattern count"
253- puts " 2. Compare how performance scales as pattern count increases"
254- puts " 3. Identify which operations are most affected by pattern count"
258+ puts ' 1. Review the iterations/second (i/s) for each pattern count'
259+ puts ' 2. Compare how performance scales as pattern count increases'
260+ puts ' 3. Identify which operations are most affected by pattern count'
255261puts "\n Note: Higher i/s (iterations per second) indicates better performance"
0 commit comments