Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Parallel for performance improvement #4

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/rogue_one/detector.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "yaml"
require "parallel"

module RogueOne
class Detector
Expand All @@ -10,7 +11,7 @@ class Detector

def initialize(target:)
@target = target
@memo = Hash.new(0)
@memo = {}
end

def report
Expand Down Expand Up @@ -38,14 +39,14 @@ def landing_pages
end

def inspect
top_100_domains.each do |domain|
results = Parallel.map(top_100_domains) do |domain|
normal_result = normal_resolver.dig(domain, "A")
target_result = target_resolver.dig(domain, "A")

if normal_result != target_result
@memo[target_result] += 1 if target_result
end
end
target_result if target_result && normal_result != target_result
end.compact

@memo = results.group_by(&:itself).map { |k, v| [k, v.length] }.to_h
end

def top_100_domains
Expand Down
1 change: 1 addition & 0 deletions rogue_one.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 12.3"
spec.add_development_dependency "rspec", "~> 3.8"

spec.add_dependency "parallel", "~> 1.17"
spec.add_dependency "thor", "~> 0.19"
end
1 change: 1 addition & 0 deletions spec/rogue_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
describe "#report" do
before do
allow(subject).to receive(:top_100_domains).and_return(%w(google.com))
allow(Parallel).to receive(:processor_count).and_return(0)
end

let(:report) { subject.report }
Expand Down