Skip to content

Commit 8d86d35

Browse files
bibengabibenga
authored andcommitted
uses clock_gettime
1 parent 7421c7f commit 8d86d35

4 files changed

Lines changed: 5 additions & 11 deletions

File tree

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
source 'https://rubygems.org'
44

55
group :development, :test do
6-
gem 'benchmark', require: false
76
gem 'bundler-audit', require: false
87
gem 'minitest', '~> 5.26'
98
gem 'rake', '~> 13.3', require: false

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ GEM
22
remote: https://rubygems.org/
33
specs:
44
ast (2.4.3)
5-
benchmark (0.5.0)
65
bundler-audit (0.9.2)
76
bundler (>= 1.2.0, < 3)
87
thor (~> 1.0)
@@ -44,7 +43,6 @@ PLATFORMS
4443
ruby
4544

4645
DEPENDENCIES
47-
benchmark
4846
bundler-audit
4947
minitest (~> 5.26)
5048
rake (~> 13.3)

examples/tsp.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
55

66
require 'optparse'
7-
require 'benchmark'
87
require 'alns'
98
require 'alns/state'
109
require 'alns/accept/hill_climbing'
@@ -56,11 +55,9 @@ def self.solve
5655
stop = ALNS::Stop::MaxIterations.new(2000)
5756
# stop = ALNS::Stop::MaxRuntime.new(2)
5857

59-
result = nil
60-
elapsed = Benchmark.measure do
61-
result = solver.iterate(init_sol, select, accept, stop)
62-
end
63-
# pp res
58+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
59+
result = solver.iterate(init_sol, select, accept, stop)
60+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
6461

6562
puts format('best solution: %.4f', result.best_state.objective)
6663

lib/alns/stop/max_runtime.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def initialize(max_runtime)
1313

1414
def done?(_rnd, _best, _current)
1515
if @started.nil?
16-
@started = Time.new
16+
@started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1717
return false
1818
end
19-
elapsed = Time.now - @started
19+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @started
2020
elapsed > @max_runtime
2121
end
2222
end

0 commit comments

Comments
 (0)