Skip to content

Commit 186294d

Browse files
committed
try parallel
1 parent 347ca35 commit 186294d

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

.github/workflows/benchmarks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: bundle install
3434
- name: Run benchmarks
3535
run: bundle exec rake
36-
- name: Generate HTML page for all versions
36+
- name: Generate Markdown page for all versions
3737
run: bundle exec rake generate_versions_html
3838

3939
publish:
@@ -43,7 +43,7 @@ jobs:
4343
- uses: actions/checkout@v3
4444
with:
4545
fetch-depth: 0
46-
- name: Copy generated HTML page
46+
- name: Copy generated Markdown page
4747
run: |
4848
cp all_versions_benchmarks.html ./
4949
touch .nojekyll
@@ -56,7 +56,7 @@ jobs:
5656
rm -rf *
5757
cp all_versions_benchmarks.html ./
5858
touch .nojekyll
59-
- name: Commit and push HTML page
59+
- name: Commit and push Markdown page
6060
run: |
6161
git add .
6262
git commit -m "Update all versions benchmark HTML [ci skip]" || echo "No changes to commit"

Rakefile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@ task :generate_versions_html do
44
end
55
desc "run benchmark in current ruby"
66
task :run_benchmark do
7+
require 'fileutils'
78
if ENV['CI'] == '1'
8-
system('mkdir', '-p', 'reports')
9-
output_to_report = ">> reports/#{RUBY_VERSION}.txt"
9+
FileUtils.mkdir_p("reports/#{RUBY_VERSION}")
1010
end
1111

12-
Dir["code/*/*.rb"].sort_by { |path| path =~ /^code\/general/ ? 0 : 1 }.each do |benchmark|
13-
command = "ruby -v -W0 #{benchmark}"
12+
benchmarks = Dir["code/*/*.rb"].sort_by { |path| path =~ /^code\/general/ ? 0 : 1 }
1413

15-
if ENV['CI'] == '1'
16-
system("echo '$ ruby -v #{benchmark}' #{output_to_report}")
17-
command += " #{output_to_report}"
14+
if ENV['CI'] == '1'
15+
# Use GNU parallel if available, else fallback to Ruby threads
16+
parallel_cmd = "parallel --will-cite --halt soon,fail=1 --jobs $(( $(nproc) )) 'ruby -v -W0 {} > reports/#{RUBY_VERSION}/{/.}.txt' ::: #{benchmarks.join(' ')}"
17+
if system('which parallel > /dev/null')
18+
puts "Running benchmarks in parallel with GNU parallel"
19+
system(parallel_cmd)
1820
else
21+
puts "GNU parallel not found, running benchmarks in Ruby threads"
22+
threads = benchmarks.map do |benchmark|
23+
Thread.new do
24+
out_file = "reports/#{RUBY_VERSION}/#{File.basename(benchmark, '.rb')}.txt"
25+
system("ruby -v -W0 #{benchmark} > #{out_file}")
26+
end
27+
end
28+
threads.each(&:join)
29+
end
30+
else
31+
benchmarks.each do |benchmark|
1932
puts "$ ruby -v #{benchmark}"
33+
system("ruby -v -W0 #{benchmark}")
2034
end
21-
22-
puts command
23-
system(command)
2435
end
2536
end
2637

0 commit comments

Comments
 (0)