Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Speed refinements within step defs

  • Loading branch information...
commit 51bbf5c12f9fc8a742ef7d004c610f03ca3c87fe 1 parent 8e833b6
@joshuaclayton authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 features/step_definitions/sieve_steps.rb
View
10 features/step_definitions/sieve_steps.rb
@@ -12,7 +12,7 @@
when ""
@result.should be_empty
else
- @primes = primes.split(",").map(&:strip).map(&:to_i)
+ @primes = primes.split(",").map {|prime| prime.to_i }
@result.should == @primes
end
end
@@ -36,7 +36,13 @@
module PrimeFileProcessor
def prime_file_process(path)
- File.new(path).read.strip.split(/\s+/).map(&:to_i)
+ @processed_cache ||= {}
+
+ if @processed_cache[path]
+ @processed_cache[path]
+ else
+ @processed_cache[path] = File.new(path).read.strip.split(/\s+/).map {|prime| prime.to_i }
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.