michaelmior /
nose-cli
| 1 | #!/usr/bin/env ruby |
||
|
0 ignored issues
–
show
coding-style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | # Get and print the seed which is used |
||
| 4 | seed = ::Random.new_seed |
||
| 5 | $stderr.puts "SEED #{seed}" |
||
|
0 ignored issues
–
show
|
|||
| 6 | ::Random.srand seed |
||
| 7 | |||
| 8 | require 'nose' |
||
| 9 | |||
| 10 | # Record times for the longest running sets of methods |
||
| 11 | times = { |
||
| 12 | indexes_for_workload: 0, |
||
| 13 | query_costs: 0, |
||
| 14 | update_costs: 0, |
||
| 15 | setup_model: 0, |
||
| 16 | solve: 0 |
||
| 17 | } |
||
| 18 | NoSE::Timer.enable do |_cls, method, time| |
||
| 19 | times[method] = time if times.key? method |
||
| 20 | end |
||
| 21 | |||
| 22 | factor = ARGV[0].to_i |
||
| 23 | |||
| 24 | # Create a random workload generator |
||
| 25 | network = NoSE::Random::WattsStrogatzNetwork.new(nodes_nb: 7 * factor) |
||
| 26 | workload = NoSE::Workload.new |
||
| 27 | network.entities.each { |entity| workload << entity } |
||
| 28 | sgen = NoSE::Random::StatementGenerator.new workload.model |
||
| 29 | |||
| 30 | # Add random queries |
||
| 31 | 1.upto(30 * factor).each do |i| |
||
| 32 | path_length = rand > 0.9 ? 2 : 1 |
||
| 33 | path_length = 3 if i <= factor |
||
| 34 | |||
| 35 | r = rand |
||
| 36 | conditions = if r > 0.95 |
||
| 37 | 3 |
||
| 38 | elsif r > 0.75 |
||
| 39 | 2 |
||
| 40 | else |
||
| 41 | 1 |
||
| 42 | end |
||
| 43 | q = sgen.random_query path_length, |
||
| 44 | 3, |
||
| 45 | conditions, |
||
| 46 | rand > 0.9 |
||
| 47 | $stderr.puts q.unparse |
||
|
0 ignored issues
–
show
|
|||
| 48 | workload.add_statement q, 10 |
||
| 49 | end |
||
| 50 | |||
| 51 | # Add random updates |
||
| 52 | 1.upto(3 * factor).each do |
||
| 53 | u = sgen.random_update 1, 2, 1 |
||
| 54 | $stderr.puts u.text |
||
|
0 ignored issues
–
show
|
|||
| 55 | workload.add_statement u |
||
| 56 | end |
||
| 57 | |||
| 58 | # Add random inserts |
||
| 59 | 1.upto(5 * factor).each do |
||
| 60 | i = sgen.random_insert |
||
| 61 | $stderr.puts i.text |
||
|
0 ignored issues
–
show
|
|||
| 62 | workload.add_statement i |
||
| 63 | end |
||
| 64 | |||
| 65 | # Uncomment the lines below to enable profiling |
||
| 66 | # (along with the lines above to save the output) |
||
| 67 | # require 'ruby-prof' |
||
| 68 | # Parallel.instance_variable_set(:@processor_count, 0) |
||
| 69 | # RubyProf.start |
||
| 70 | |||
| 71 | # Execute NoSE for the random workload and report the time |
||
| 72 | start = Time.now.utc |
||
| 73 | indexes = NoSE::IndexEnumerator.new(workload).indexes_for_workload.to_a |
||
| 74 | search = NoSE::Search::Search.new(workload, |
||
| 75 | NoSE::Cost::RequestCountCost.new) |
||
| 76 | search.search_overlap(indexes) |
||
| 77 | elapsed = Time.now.utc - start |
||
| 78 | |||
| 79 | # Output the timing values |
||
| 80 | total = 0 |
||
| 81 | times[:costs] = times.delete(:query_costs) + times.delete(:update_costs) |
||
| 82 | times.each do |key, time| |
||
| 83 | puts "#{key},#{time}" |
||
| 84 | total += time |
||
| 85 | end |
||
| 86 | puts "other,#{elapsed - total}" |
||
| 87 | |||
| 88 | # Uncomment the lines below to save profile output |
||
| 89 | # (along with the lines above to enable profiling) |
||
| 90 | # result = RubyProf.stop |
||
| 91 | # result.eliminate_methods!([ |
||
| 92 | # /NoSE::Field#hash/, |
||
| 93 | # /Range#/, |
||
| 94 | # /Array#/, |
||
| 95 | # /Set#/, |
||
| 96 | # /Hash#/, |
||
| 97 | # /Integer#downto/, |
||
| 98 | # /Hashids#/, |
||
| 99 | # /String#/, |
||
| 100 | # /Enumerable#/, |
||
| 101 | # /Integer#times/, |
||
| 102 | # /Class#new/ |
||
| 103 | # ]) |
||
| 104 | # printer = RubyProf::CallTreePrinter.new(result) |
||
| 105 | # printer.print(File.open('prof.out', 'w')) |
||
| 106 |