Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Add performance tests to show difference with/without stop condition
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Nov 1, 2019
1 parent ae0ae2e commit e005c4a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions spec/performance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "spec_helper"
require 'benchmark'

RSpec.describe TappingDevice::Device do
let(:devices) do
devices = []
100.times { devices << TappingDevice::Device.new }
devices
end

after do
devices.each(&:stop!)
end

context "without stop_when" do
it "takes long time when tapping multiple devices" do
time = Benchmark.realtime do
devices.each do |device|
s = Student.new("foo", 10)
device.tap_on!(s)
10.times { s.name }

expect(device.calls.count).to eq(10)
end
end
devices.each { |d| d.stop! }
expect(time).to be_between(4, 10)
end
end

context "with stop_when" do
it "takes very short time when tapping multiple devices" do
time = Benchmark.realtime do
devices.each do |device|
device.stop_when do
device.calls.count == 10
end

s = Student.new("foo", 10)
device.tap_on!(s)
10.times { s.name }

expect(device.calls.count).to eq(10)
end
end

devices.each { |d| d.stop! }
expect(time).to be_between(0, 1)
end
end
end

0 comments on commit e005c4a

Please sign in to comment.