-
-
Notifications
You must be signed in to change notification settings - Fork 753
Conversation
Seems legit to me |
This needs the RSpec support PR merging first, but then I think it will work. |
Restarted the build to find out ;) |
Ah, emails came in out of order. I see that you've merged it now :) |
Maybe this is something that should be moved to |
Dir.mkdir(File.join(stack)) | ||
rescue Errno::EISDIR | ||
rescue Errno::EEXIST | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we aren't building long paths. However, why not make stack
a String
:
stack = ""
if stack.empty? && part == ""
stack = File::SEPARATOR # This may have issues on Windows??
else
stack = File.join(stack, part)
end
Then there's no need to keep re-joining the path parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 that's much better. Thanks for the tip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since in most cases where we have multiple directories to check (ala rspec-rails
) most of the path will already exist. If we check for the directory existence first instead of letting the error bubble up, the perf improves ~4x:
# Benchmarking code
require "benchmark"
require "benchmark/ips"
require "tmpdir"
require 'fileutils'
TMPDIR = 'tempdir'
TMPFILE = 'tempfile'
Dir.mktmpdir do |dir|
FileUtils.chdir dir
FileUtils.touch TMPFILE
FileUtils.mkdir TMPDIR
Benchmark.ips do |r|
r.report("Dir: check first") do
Dir.mkdir(TMPDIR) unless File.exist?(TMPDIR)
end
r.report("Dir: with rescue") do
begin
Dir.mkdir(TMPDIR)
rescue
end
end
r.report("File: check first") do
Dir.mkdir(TMPFILE) unless File.exist?(TMPFILE)
end
r.report("File: with rescue") do
begin
Dir.mkdir(TMPFILE)
rescue
end
end
end
end
Calculating -------------------------------------
Dir: check first 24961 i/100ms
Dir: with rescue 9387 i/100ms
File: check first 26349 i/100ms
File: with rescue 9232 i/100ms
-------------------------------------------------
Dir: check first 498909.9 (±14.2%) i/s - 2446178 in 5.031855s
Dir: with rescue 110663.3 (±8.5%) i/s - 553833 in 5.045112s
File: check first 483680.0 (±14.0%) i/s - 2371410 in 5.018733s
File: with rescue 110862.5 (±10.1%) i/s - 553920 in 5.054816s
I ran this on my 2012 MacBook Air 1.8 GHz i5 with 8GB 1600MHz DDR3 using Ruby 2.1.1.
I've moved the directory maker into RSpec Support and added some tests over there, I also applied @cupakromer's suggested improvements on that implementation. |
LGTM merge when support is ready. |
Let's leave it until 3.0.0 is done? |
Yeah sure, I don't have a real opinion either way, it should just be an internal refactor and not a change in external behavior. |
I suspect @myronmarston will side with Sam here and say ship it after 3 ships. |
Yep :). Not worth the risk it introduces. |
Is this still good to merge? Does it need a changelog entry? |
Needs a changelog entry and to be squashed, but looks good otherwise. |
We now use our own implementation: RSpec::Support::DirectoryMaker instead which implements mkdir_p for us.
Conflicts: Changelog.md
Conflicts: Changelog.md
Remove fileutils
Series of commits removing dependencies on fileutils. I think I got them all. Fixes #1564