Skip to content
Newer
Older
100644 49 lines (40 sloc) 1.48 KB
9bfeb5a @lsegal Add benchmark to show lookup speed between normal registry and one se…
authored
1 require 'benchmark'
2 require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
3
4 def parse_and_select_objects
5 YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
6 YARD::Registry.load_all
7 $paths = []
8 4.times { $paths << YARD::Registry.paths[rand(YARD::Registry.paths.size)] }
fa147d9 @lsegal The great whitespace fix of 2012
authored
9
9bfeb5a @lsegal Add benchmark to show lookup speed between normal registry and one se…
authored
10 $regular_registry = {}
11 $types_registry = {}
12 YARD::Registry.all.each do |object|
13 $regular_registry[object.path] = object
14 ($types_registry[object.type] ||= {})[object.path] = object
15 end
16 end
17
18 def run_lookup
19 $paths.select {|path| $regular_registry[path] }
20 end
21
22 def run_lookup_with_types
23 $paths.select {|path| $types_registry.values.find {|list| list[path] } }
24 end
25
26 TIMES = 100_000
27
28 parse_and_select_objects
29 p $paths
30 Benchmark.bmbm do |x|
31 x.report("normal") { TIMES.times { run_lookup } }
32 x.report("types") { TIMES.times { run_lookup_with_types } }
33 end
34
35 __END__
36 # Run on March 22 2012
fa147d9 @lsegal The great whitespace fix of 2012
authored
37 ["YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar#initialize",
38 "YARD::Parser::C::CParser#enumerator",
39 "YARD::CodeObjects::ClassObject#inherited_meths",
9bfeb5a @lsegal Add benchmark to show lookup speed between normal registry and one se…
authored
40 "YARD::Parser::C::Statement#source="]
41 Rehearsal ----------------------------------------------
42 normal 0.180000 0.000000 0.180000 ( 0.182640)
43 types 1.150000 0.010000 1.160000 ( 1.160219)
44 ------------------------------------- total: 1.340000sec
45
46 user system total real
47 normal 0.170000 0.000000 0.170000 ( 0.165621)
48 types 1.140000 0.000000 1.140000 ( 1.142269)
Something went wrong with that request. Please try again.