diff --git a/Rakefile b/Rakefile index 378dab3..c79ed06 100644 --- a/Rakefile +++ b/Rakefile @@ -2,4 +2,9 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task default: :spec +task default: [:spec, :performance_test] + +desc 'Check performance' +task :performance_test do + ruby 'scripts/command_performance.rb' +end diff --git a/expeditor.gemspec b/expeditor.gemspec index 38d4d47..793da3e 100644 --- a/expeditor.gemspec +++ b/expeditor.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "concurrent-ruby", ">= 1.0.0" spec.add_runtime_dependency "retryable", "> 1.0" + spec.add_development_dependency "benchmark-ips" spec.add_development_dependency "bundler" spec.add_development_dependency "concurrent-ruby-ext", ">= 1.0.0" spec.add_development_dependency "rake" diff --git a/scripts/command_performance.rb b/scripts/command_performance.rb new file mode 100644 index 0000000..90aed19 --- /dev/null +++ b/scripts/command_performance.rb @@ -0,0 +1,25 @@ +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) +require 'expeditor' + +require 'benchmark/ips' + +Benchmark.ips do |x| + x.report("simple command") do |i| + executor = Concurrent::ThreadPoolExecutor.new(min_threads: 100, max_threads: 100, max_queue: 100) + service = Expeditor::Service.new(period: 10, non_break_count: 0, threshold: 0.5, sleep: 1, executor: executor) + + i.times do + commands = 10000.times.map do + Expeditor::Command.new { 1 }.start + end + command = Expeditor::Command.new(service: service, dependencies: commands) do |*vs| + vs.inject(0, &:+) + end.start + command.get + + service.reset_status! + end + end + + x.compare! +end