Skip to content

Commit

Permalink
Update benchmark script
Browse files Browse the repository at this point in the history
  • Loading branch information
pusewicz committed May 6, 2024
1 parent eea1096 commit a3fc9df
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ Run `bin/run` to run the example.

## Benchmark

Run `ruby test/benchmark.rb` to see how fast the algorithm is.
Run `bin/benchmark` to see how fast the algorithm is.

#### Apple M3 Max 64GB (2023): 12.437260s

$ ruby test/benchmark.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Running benchmark for Model(grid=20x20 entropy=188)...
12.362356 0.020133 12.382489 ( 12.437260)
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Run #1: Benchmark for Model(grid=20x20 entropy=188)… Finished in 11.65s
Run #2: Benchmark for Model(grid=20x20 entropy=188)… Finished in 13.46s
Run #3: Benchmark for Model(grid=20x20 entropy=188)… Finished in 11.89s
Average time: 12.33499966666568
Slowest time: 13.458501000000979
Fastest time: 11.65374900000461

## Contributing

Expand Down
41 changes: 41 additions & 0 deletions bin/benchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)

require "benchmark"
require "json"
require "wave_function_collapse"

WIDTH = 20
HEIGHT = 20

json = JSON.load_file!("assets/map.tsj")
tiles =
json["wangsets"].last["wangtiles"].map do |tile|
prob = json["tiles"]&.find { |t| t["id"] == tile["tileid"] }&.fetch("probability")
WaveFunctionCollapse::Tile.new(
tileid: tile["tileid"],
wangid: tile["wangid"],
probability: prob
)
end
times = []

puts RUBY_DESCRIPTION

times = 3.times.map { |i|
time = Benchmark.realtime {
model = WaveFunctionCollapse::Model.new(tiles, WIDTH, HEIGHT)
print "Run ##{i + 1}: Benchmark for Model(grid=#{model.width}x#{model.height} entropy=#{model.max_entropy})… "
until model.complete?
model.solve
end
}
puts "Finished in #{time.round(2)}s"
time
}

puts "Average time: #{times.sum / times.size}"
puts "Slowest time: #{times.max}"
puts "Fastest time: #{times.min}"
28 changes: 0 additions & 28 deletions test/benchmark.rb

This file was deleted.

0 comments on commit a3fc9df

Please sign in to comment.