Deduplicate runtime tracking in result computation

This commit is contained in:
Markus Schirp 2014-07-14 14:04:08 +00:00
parent d21ff3df49
commit d6eeff7a57
3 changed files with 31 additions and 22 deletions

View file

@ -1,3 +1,3 @@
--- ---
threshold: 18 threshold: 18
total_score: 1039 total_score: 1053

View file

@ -54,6 +54,18 @@ module Mutant
end end
memoize name memoize name
end end
# Compute result tracking runtime
#
# @return [Result]
#
# @api private
#
def compute
start = Time.now
new(yield.merge(runtime: Time.now - start))
end
end # ClassMethods end # ClassMethods
# Test if operation is failing # Test if operation is failing

View file

@ -18,13 +18,12 @@ module Mutant
progress(env) progress(env)
start = Time.now @result = Result::Env.compute do
{
@result = Result::Env.new( env: env,
env: env, subject_results: visit_collection(env.subjects, &method(:run_subject))
subject_results: visit_collection(env.subjects, &method(:run_subject)), }
runtime: Time.now - start end
).tap(&config.reporter.method(:report))
end end
# Return result # Return result
@ -44,11 +43,12 @@ module Mutant
# @api private # @api private
# #
def run_subject(subject) def run_subject(subject)
Result::Subject.new( Result::Subject.compute do
subject: subject, {
mutation_results: visit_collection(subject.mutations, &method(:run_mutation)), subject: subject,
runtime: nil mutation_results: visit_collection(subject.mutations, &method(:run_mutation))
) }
end
end end
# Run mutation # Run mutation
@ -60,15 +60,12 @@ module Mutant
# @api private # @api private
# #
def run_mutation(mutation) def run_mutation(mutation)
start = Time.now Result::Mutation.compute do
{
test_results = kill_mutation(mutation) mutation: mutation,
test_results: kill_mutation(mutation)
Result::Mutation.new( }
mutation: mutation, end
runtime: Time.now - start,
test_results: test_results
)
end end
# Kill mutation # Kill mutation