This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjar_benchmarker.rb
109 lines (95 loc) · 2.64 KB
/
jar_benchmarker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
require_relative 'benchmarker.rb'
class JarBenchmarker < Benchmarker
def initialize(jar_files)
super()
@jar_files = jar_files
#puts @jar_files
end
def run_pairs
tasks = []
# open pairs file
# for each pair
# run command
# benchmark
# store results
# close file
# print results
pairs = File.open("var/example/random_sequences.pairs", "r")
pairs.each do |pair|
seq1, seq2 = pair.split(":")
# wrtie temporary pairs file
File.open("var/example/tmp.pairs", "w") do |file|
file.puts "#{seq1} #{seq2}"
end
@jar_files.each do |jar|
jar.each do |j|
if j == "commands"
next
else
java = j.find {|h| h.key?("java")}["java"]
rounds = j.find {|h| h.key?("iterations")}["iterations"]
cases = j.select {|h| h.key?("path")}
cases.each do |cs|
path = cs["path"]
args = cs["args"]
uri = ""
command = "#{java}java.exe -jar #{path} "
args.each do |k,v|
if k == "--nw"
command << "--nw "
next
elsif k == "--uri"
uri = v
next
end
command << "#{k} #{v} "
puts "Command: #{command}"
end
tasks << {uri: uri, command: command, rounds: rounds}
end
end
end
end
end
end
def run
tasks = []
@jar_files.each do |jar|
#p jar
jar.each do |j|
if j == "commands"
next
else
java = j.find {|h| h.key?("java")}["java"]
rounds = j.find {|h| h.key?("iterations")}["iterations"]
cases = j.select {|h| h.key?("path")}
cases.each do |cs|
path = cs["path"]
args = cs["args"]
uri = ""
command = "#{java}java.exe -jar #{path} "
args.each do |k,v|
if k == "--nw"
command << "--nw "
next
elsif k == "--uri"
uri = v
next
end
command << "#{k} #{v} "
puts "Command: #{command}"
end
tasks << {uri: uri, command: command, rounds: rounds}
end
end
end
tasks.each do |task|
benchmark(task[:command], task[:uri], task[:rounds]) do
#system("#{task[:command]} > #{Gem.win_platform? ? 'NUL' : '/dev/null'} 2>&1")
system(task[:command])
end
end
end
end
end