This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance tests to show difference with/without stop condition
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |