Skip to content

Commit

Permalink
Remove benchmark dependency
Browse files Browse the repository at this point in the history
Ruby wants to bundle it: ruby/ruby#11492

This is pretty much all the gem does anyways: https://github.com/ruby/benchmark/blob/8d2c8a0d7ca72bff7e97a4800e16c72f232867e4/lib/benchmark.rb#L311-L315

I removed the `bench_cop` rake task since it uses `benchmark` and I believe it just isn't very useful.
Dedicated tools like `vernier` or `stackprof` (which has buildin support in RuboCop these days)
are much more suited for the task.
  • Loading branch information
Earlopain authored and bbatsov committed Aug 29, 2024
1 parent 5811e62 commit 91fed8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
43 changes: 0 additions & 43 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,6 @@ task default: %i[documentation_syntax_check spec prism_spec internal_investigati
require 'yard'
YARD::Rake::YardocTask.new

desc 'Benchmark a cop on given source file/dir'
task :bench_cop, %i[cop srcpath times] do |_task, args|
require 'benchmark'
require 'rubocop'
include RuboCop
include RuboCop::Formatter::TextUtil

cop_name = args[:cop]
src_path = args[:srcpath]
iterations = args[:times] ? Integer(args[:times]) : 1

cop_class = if cop_name.include?('/')
Cop::Registry.all.find { |klass| klass.cop_name == cop_name }
else
Cop::Registry.all.find { |klass| klass.cop_name[/[a-zA-Z]+$/] == cop_name }
end
raise "No such cop: #{cop_name}" if cop_class.nil?

config = ConfigLoader.load_file(ConfigLoader::DEFAULT_FILE)
cop = cop_class.new(config)

puts "Benchmarking #{cop.cop_name} on #{src_path} (using default config)"

files = if File.directory?(src_path)
Dir[File.join(src_path, '**', '*.rb')]
else
[src_path]
end

puts "(#{pluralize(iterations, 'iteration')}, #{pluralize(files.size, 'file')})"

ruby_version = RuboCop::TargetRuby.supported_versions.last
srcs = files.map { |file| ProcessedSource.from_file(file, ruby_version) }

puts 'Finished parsing source, testing inspection...'
puts(Benchmark.measure do
iterations.times do
commissioner = Cop::Commissioner.new([cop], [])
srcs.each { |src| commissioner.investigate(src) }
end
end)
end

desc 'Syntax check for the documentation comments'
task documentation_syntax_check: :yard_for_generate_documentation do
require 'parser/ruby25'
Expand Down
7 changes: 4 additions & 3 deletions exe/rubocop
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ exit exit_status if server_cli.exit?
if RuboCop::Server.running?
exit_status = RuboCop::Server::ClientCommand::Exec.new.run
else
require 'benchmark'
require 'rubocop'

cli = RuboCop::CLI.new

time = Benchmark.realtime { exit_status = cli.run }
time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
exit_status = cli.run
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start

puts "Finished in #{time} seconds" if cli.options[:debug] || cli.options[:display_time]
puts "Finished in #{elapsed_time} seconds" if cli.options[:debug] || cli.options[:display_time]
end
exit exit_status

0 comments on commit 91fed8c

Please sign in to comment.