Skip to content

Commit

Permalink
Added a performance test in order to compare speed and memory usage o…
Browse files Browse the repository at this point in the history
…f the two different approaches (+ vs add)
  • Loading branch information
iwan committed Jul 17, 2018
1 parent 7532f1c commit 5fc1727
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/performance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'memory_profiler'

RSpec.describe "Performance" do

it "sum 'in place'" do
t = Time.now
report = MemoryProfiler.report do
ya = Yarray.new(2018)
1.upto(1000).each do |n|
ya.add(Yarray.new(2018, value: n))
end
puts ya.to_s
end
puts Time.now-t
report.pretty_print
end

it "result of sum in a new yarray" do
t = Time.now
report = MemoryProfiler.report do
ya = Yarray.new(2018)
1.upto(1000).each do |n|
ya += Yarray.new(2018, value: n)
end
puts ya.to_s
end
puts Time.now-t
report.pretty_print
end
end

0 comments on commit 5fc1727

Please sign in to comment.