|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -# Galtzo FLOSS Rakefile v1.0.2 - 2025-08-12 |
| 3 | +# Galtzo FLOSS Rakefile v1.0.3 - 2025-08-14 |
4 | 4 | #
|
5 | 5 | # MIT License (see License.txt)
|
6 | 6 | #
|
|
10 | 10 | #
|
11 | 11 | # Sets up tasks for rspec, minitest, rubocop, reek, yard, and stone_checksums.
|
12 | 12 | #
|
| 13 | +# rake bench # Run all benchmarks (alias for bench:run) |
| 14 | +# rake bench:list # List available benchmark scripts |
| 15 | +# rake bench:run # Run all benchmark scripts (skips on CI) |
13 | 16 | # rake build # Build my_gem-1.0.0.gem into the pkg directory
|
14 | 17 | # rake build:checksum # Generate SHA512 checksum of my_gem-1.0.0.gem into the checksums directory
|
15 | 18 | # rake build:generate_checksums # Generate both SHA256 & SHA512 checksums into the checksums directory, and git commit them
|
|
30 | 33 | # rake rubocop_gradual:check # Run RuboCop Gradual to check the lock file
|
31 | 34 | # rake rubocop_gradual:force_update # Run RuboCop Gradual to force update the lock file
|
32 | 35 | # rake spec # Run RSpec code examples
|
33 |
| -# rake test # Run tests / run spec task with test task |
| 36 | +# rake test # Run tests |
34 | 37 | # rake yard # Generate YARD Documentation
|
35 | 38 |
|
36 | 39 | require "bundler/gem_tasks"
|
| 40 | +require "rbconfig" |
37 | 41 |
|
38 | 42 | defaults = []
|
39 | 43 |
|
@@ -198,4 +202,57 @@ rescue LoadError
|
198 | 202 | end
|
199 | 203 | end
|
200 | 204 |
|
| 205 | +# --- Benchmarks (dev-only) --- |
| 206 | +namespace :bench do |
| 207 | + desc "List available benchmark scripts" |
| 208 | + task :list do |
| 209 | + bench_files = Dir[File.join(__dir__, "benchmarks", "*.rb")].sort |
| 210 | + if bench_files.empty? |
| 211 | + puts "No benchmark scripts found under benchmarks/." |
| 212 | + else |
| 213 | + bench_files.each { |f| puts File.basename(f) } |
| 214 | + end |
| 215 | + end |
| 216 | + |
| 217 | + desc "Run all benchmark scripts (skips on CI)" |
| 218 | + task :run do |
| 219 | + if ENV.fetch("CI", "false").casecmp("true").zero? |
| 220 | + puts "Benchmarks are disabled on CI. Skipping." |
| 221 | + next |
| 222 | + end |
| 223 | + |
| 224 | + ruby = RbConfig.ruby |
| 225 | + bundle = Gem.bindir ? File.join(Gem.bindir, "bundle") : "bundle" |
| 226 | + bench_files = Dir[File.join(__dir__, "benchmarks", "*.rb")].sort |
| 227 | + if bench_files.empty? |
| 228 | + puts "No benchmark scripts found under benchmarks/." |
| 229 | + next |
| 230 | + end |
| 231 | + |
| 232 | + use_bundler = ENV.fetch("BENCH_BUNDLER", "0") == "1" |
| 233 | + |
| 234 | + bench_files.each do |script| |
| 235 | + puts "\n=== Running: #{File.basename(script)} ===" |
| 236 | + if use_bundler |
| 237 | + cmd = [bundle, "exec", ruby, "-Ilib", script] |
| 238 | + system(*cmd) || abort("Benchmark failed: #{script}") |
| 239 | + else |
| 240 | + # Run benchmarks without Bundler to reduce overhead and better reflect plain ruby -Ilib |
| 241 | + begin |
| 242 | + require "bundler" |
| 243 | + Bundler.with_unbundled_env do |
| 244 | + system(ruby, "-Ilib", script) || abort("Benchmark failed: #{script}") |
| 245 | + end |
| 246 | + rescue LoadError |
| 247 | + # If Bundler isn't available, just run directly |
| 248 | + system(ruby, "-Ilib", script) || abort("Benchmark failed: #{script}") |
| 249 | + end |
| 250 | + end |
| 251 | + end |
| 252 | + end |
| 253 | +end |
| 254 | + |
| 255 | +desc "Run all benchmarks (alias for bench:run)" |
| 256 | +task bench: "bench:run" |
| 257 | + |
201 | 258 | task default: defaults
|
0 commit comments