Skip to content

Commit ccaf789

Browse files
committed
Make lee benchmark ractor compatible
1 parent c1c1654 commit ccaf789

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ graphql-native:
7171
desc: GraphQL gem parsing a large file, but using a native parser
7272
lee:
7373
desc: lee is a circuit-board layout solver, deployed in a plausibly reality-like way
74+
ractor: true
7475
nbody:
7576
desc: nbody from the Computer Language Benchmarks Game.
7677
ractor: true

benchmarks/lee/benchmark.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,34 @@ def lay(depth, solution)
8787
Dir.chdir __dir__
8888
use_gemfile
8989

90+
BOARD = Ractor.make_shareable(board)
91+
OBSTRUCTED = Ractor.make_shareable(obstructed)
92+
OUTPUT_FILENAME = Ractor.make_shareable(output_filename)
93+
EXPANSIONS_DIR = Ractor.make_shareable(expansions_dir)
94+
9095
run_benchmark(10) do
91-
depth = Lee::Matrix.new(board.height, board.width)
96+
depth = Lee::Matrix.new(BOARD.height, BOARD.width)
9297

9398
solutions = {}
9499

95-
board.routes.each do |route|
96-
cost = expand(board, obstructed, depth, route)
97-
solution = solve(board, route, cost)
100+
BOARD.routes.each do |route|
101+
cost = expand(BOARD, OBSTRUCTED, depth, route)
102+
solution = solve(BOARD, route, cost)
98103

99-
if expansions_dir
100-
Lee.draw board, solutions.values, [[cost.keys, solution]], File.join(expansions_dir, "expansion-#{route.object_id}.svg")
104+
if EXPANSIONS_DIR
105+
Lee.draw BOARD, solutions.values, [[cost.keys, solution]], File.join(EXPANSIONS_DIR, "expansion-#{route.object_id}.svg")
101106
end
102107

103108
lay depth, solution
104109
solutions[route] = solution
105110
end
106111

107-
raise 'invalid solution' unless Lee.solution_valid?(board, solutions)
112+
raise 'invalid solution' unless Lee.solution_valid?(BOARD, solutions)
108113

109-
cost, depth = Lee.cost_solutions(board, solutions)
110-
#puts "routes: #{board.routes.size}"
114+
cost, depth = Lee.cost_solutions(BOARD, solutions)
115+
#puts "routes: #{BOARD.routes.size}"
111116
#puts "cost: #{cost}"
112117
#puts "depth: #{depth}"
113118

114-
Lee.draw board, solutions.values, output_filename if output_filename
119+
Lee.draw BOARD, solutions.values, OUTPUT_FILENAME if OUTPUT_FILENAME
115120
end

0 commit comments

Comments
 (0)