-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathbench.rb
53 lines (42 loc) · 1005 Bytes
/
bench.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
#!/usr/bin/env ruby
require "zlib"
if ARGV.size != 1
puts "Usage: ruby #{$0} routing_executable"
exit(-1)
end
def consume_answer(io)
line = io.gets.strip
if line != "NO_SOLUTION"
while !line.empty?
line = io.gets.strip
end
end
end
puts "Loading top stations"
top_stations = File.open("stations").map { |id| id.to_i }
puts "… done\n\n"
puts "Starting the application"
io = IO.popen ARGV[0], "r+"
puts "… done\n\n"
puts "Loading the data"
Zlib::GzipReader::open("bench_data_48h.gz").each { |line| io.write line }
io.write "\n"
puts "… done\n\n"
puts "Starting the benchmark"
count = 0
start_time = Time.now
top_stations.each do |station|
io.puts "#{station} #{top_stations.first} 0"
consume_answer io
count += 1
end
io.write "\n"
duration = Time.now - start_time
puts "… done\n\n"
puts "Total time: #{duration} seconds"
puts "Average time per search: #{duration * 1000 / count} ms"
begin
io.close
rescue Errno::EPIPE
# Prevent broken pipe errors
end